From the course: Programming for Non-programmers: iOS 17 and Swift 5

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Showing the total when the equals button is tapped

Showing the total when the equals button is tapped

From the course: Programming for Non-programmers: iOS 17 and Swift 5

Showing the total when the equals button is tapped

- [Instructor] Now we're going to do what happens when the equals button is pressed. Remember we have a number entered before the operation button was pressed and a number that was entered after. The before number was savedInt while the after number, or current number in the calculator, is currentInt. So with that in mind, let's go down a few lines below the if statement in the equalWasPressed method, and then we're going to create a conditional statement that checks if the current mode is equal to addition. So if currentMode is equal to, so two equal signs and then .addition and then some curly braces. If that's the case, we're going to add our two numbers together. So savedInt, that's the first number, +=, in other words, increment by the amount of, and then a space, and then currentInt, the current value that is in the calculator. So if we have one, two, three as the integer that we entered before pressing the plus button and four, five, six currently in the calculator, this would…

Contents