A simple Calculator
Here in the above diagram we can see
There are Four labels used Enter the first number- Label1 Enter the second number-Label2 Select the operation-Label3 lblresult-> this label is used during runtime for displaying the result. To select the operator a dropdown list tool is used. And lastly and most importantly the button named “Calculate” is used .The main program code is written here. Program Source Code: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btncalculate_Click(object sender, EventArgs e) { int num1 = int.Parse(txtnum1.Text); int num2 = int.Parse(txtnum2.Text); string op = ddloperation.SelectedItem.Text; int result = 0; if (op.Equals("+")) { result = num1 + num2; } if (op.Equals("-")) { result = num1 - num2; } if (op.Equals("/")) { result = num1 / num2; } if (op.Equals("X")) { result = num1 * num2; } lblresult.Text = num1.ToString() + op + num2.ToString() + "=" + result.ToString(); } } |
|