I need to make a simple calculator that just does addition and subtraction. But the program should keep a running total of the calculations entered like this:
sum = 0
12 + 3
sum = 15
5-2
sum = 12
1+1
sum = 13
But it also needs to have an UNDO command which removes the last calculation from the sum as if it never executed. The number of UNDO levels is unlimited, so it is possible to use the UNDO command to UNDO all of the operations back to the initial state of the program.
I have so far the code on how to do the calculations, and I am trying to use stacks as the undo function. I think the stack push method works to put the sum on top, but when I try to use the pop method to remove from the top, I can't get it to output correctly. How can I change that to make it work ?
Thanks