The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 57 Weeks Ago, 1 Day Ago |
| Questions Answered: | 7570 |
| Tutorials Posted: | 7352 |
BS,MBA, PHD
Adelphi University/Devry
Apr-2000 - Mar-2005
HOD ,Professor
Adelphi University
Sep-2007 - Apr-2017
iLab 3 of 6: The Calculator (Part 3)
Last week, we created the buildNumber( ) procedure that allowed us to take button click events and convert them to numbers saved to the calculator's display label. We need to modify the buildNumber( ) procedure to allow the display to be reset and display a new number after the user has pressed an Operator button.
The blnStartNewNumber variable tells us when the user entry should start a new number or add to an existing number. Whenever a user presses an Operator button, the value of blnStartNewNumber will be set to true, and the next number pressed by the user will clear the display and begin a new number; otherwise, the number will be concatenated to the number in the display.
To complete the logic for the buildNumber( ) procedure, we must add an if-statement that tests blnStartNewNumber and takes the appropriate action to either start a new number or add to the current number.
We check to see if the operation was a percent or a square root. If it is, we do something different. If not, we need to discover the previous operation. Our global variable "strOp" tells us that. If it is clear, then this is the first number of our operation, and we can simply store it as our running total in the variable dblTotal. If it is not "clear", then it is either "add", "subtract", "multiply", or "divide" and we need to perform the proper operation.
MIS----------- 57-----------4 W-----------eek----------- 3 -----------iLa-----------b T-----------he -----------Cal-----------cul-----------ato-----------r (-----------Par-----------t 3-----------)-----------