That is your switch
error. You forget the break
after each case
. Check all your switch and test again.
- (IBAction)CalculateButton:(id)sender {
if (RunningTotal == 0) {
RunningTotal = SelectNumber;
}
else{
switch (Method) {
case 1:
RunningTotal = RunningTotal + SelectNumber;
break;
case 2:
RunningTotal = RunningTotal - SelectNumber;
case 3:
RunningTotal = RunningTotal * SelectNumber;
case 4:
RunningTotal = RunningTotal / SelectNumber;
default:
break;
}
}
......
}
Another suggestion is you don't need to create one action for every number button. You could simply link all the number button to one called:DigitButton:
. Then in the method you could get the title of the button to know what digit is select by user.(Or by tag
property if you want)