Tuesday, July 14, 2009

Creating a very, very simple calculator in C# and need coding help...?

I'm going through a C# tutorial and am trying to create a very simple calculator. You type one floating point number into a textbox (Number1) and another floating point number into another textbox (Number2) and then click a button named CALCULATE. The sum of Number1 and Number2 should then display in a read-only textbox called Sum.





I've created the form, but need help figuring out the syntax of the code that should be applied to the Calculate button.





Also, what code should go under the "Clear" button to then clear all of the boxes?

Creating a very, very simple calculator in C# and need coding help...?
Calculate:





double result = Double.Parse(Number1.Text) + Double.Parse(Number2.Text);


Sum.Text = result.ToString();





If you were doing this "for real", you would also want error checking/catching in the event that the textboxes are blank, or do not contain numbers.





========


Clear:


Number1.Text = "";


Number2.Text = "";


Sum.Text = "";


No comments:

Post a Comment