C# Calculator
C# Calculator
This allows the population of the text box by the button presses.
We need a variable to hold the first value that
the user inputs
Let’s use a double for the datatype
A double has two advantages
◦ It allows for big numbers
◦ It allows for a decimal point
This is our first math function button
This will not actually do the calculation
Calculations will be saved for the equals
button.
This code does several things:
◦ Allows for more than two numbers to be acted upon
◦ Converts the string to a number (Parse)
◦ Clears the text box for the next input
Adding a number to itself is a common task
in programming, so a shortcut is commonly
used: +=
This button will do the work. This will develop
over several stages.
This adds the two numbers together
Again, parsing converts strings to numbers
It resets the first variable to zero for adding
several numbers together
To include other functions such as subtract,
multiply and divide, how will the calculator
know that we have chosen a different
function?
We require conditional statements
A boolean (bool) is a datatype that has only
two states…..true/false
We need to test the conditional boolean
statements in the equals button and then
supply the code for the correct function
This requires if/else if statements so that we
can test for all conditions