Hi,
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, but I need help with keeping a running total and the UNDO command. Thank you.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double firstNum, secondNum; // Operands
char oper; // Operator
int result; // Resulting value
while (cin >> firstNum >> oper >> secondNum)
{
switch (oper)
{
case '+': result = firstNum + secondNum;
break;
case '-': result = firstNum - secondNum;
break;
default : cout << "Bad operator '" << oper << "'" << endl;
continue; // Start next loop iteration.
}
cout << result << endl << endl;
}
system("pause");
return 0;
}