Simple Calculator

IntroductionWindows form application mimicing the functionality of a handheld calculator. It supports all basic functionality of calculator such as Addition, Subtraction, Multiplication, Division, Square Root etc. This solution can be used by beginners who are trying to learn C

C# (60.8 KB)
 
 
 
 
 
5 Star
(3)
16,991 times
Add to favorites
4/21/2011
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 555-555-0199@example.com
    1 Posts | Last post October 13, 2017
    • 555-555-0199@example.com
  • it is not adding more numbers at a time..
    1 Posts | Last post March 15, 2015
    • for example:
      if I add 2 and 3 its ok.
      but if I perform peration: 2+3+4= then it gives only 7 i.e. 3+4
  • Running the program?
    1 Posts | Last post November 17, 2014
    • Does anyone actually have the code to make this run? I have even tried pasting this code into visual studio and when it runs it doesn't display anything. Does anyone have any answers?
  • Code problems
    2 Posts | Last post January 17, 2013
    • Suggestion 1:
      
      I would change
      
             void btn_Click(object sender, EventArgs e)
              {
                  try
                  {
                      Button btn = sender as Button;
      
                      switch (btn.Name)
                      {
                          case "btnOne":
                              txtInput.Text += "1";
                              break;
      ...
                          case "btnZero":
                              txtInput.Text += "0";
                              break;
                          case "btnDot":
                              if(!txtInput.Text.Contains("."))
                                  txtInput.Text += ".";
                              break;
      
                      }
                  }
                  catch(Exception ex)
                  {
                      MessageBox.Show("Sorry for the inconvenience, Unexpected error occured. Details: " +
                          ex.Message);
                  }
              }
      
      to
      
              void btn_Click(object sender, EventArgs e)
              {
                  try
                  {
                      Button btn = sender as Button;
                      if (!((btn.Text==".")&&(txtInput.Text.Contains(".")))) 
                          txtInput.Text += btn.Text;
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show("Sorry for the inconvenience, Unexpected error occured. Details: " +
                          ex.Message);
                  }
      
    • What is the background of that change?
  • Code problems 2.
    1 Posts | Last post September 07, 2012
    • Problem 1:
      
            private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
      
      Is not correct.
      
      Problem2:
      
              private void txtInput_TextChanged(object sender, EventArgs e)
              {
                  
              }
      
      Is empty.
      
      Suggestion:
      
             private void btnPlus_Click(object sender, EventArgs e)
      and
              private void btnMinus_Click(object sender, EventArgs e)
      etc. could be generalized similarly to what I shown in suggestion 1.
      
      
      Problem 3:
              private void btnSqrRoot_Click(object sender, EventArgs e)
              {
                  double opr1;
                  if (double.TryParse(txtInput.Text, out opr1))
                  {
                      txtInput.Text = (Math.Sqrt(opr1)).ToString();
                  }
              }
      
      Does not check for square root of negative numbers.