/*************************************************** A Very Simple Calculator Write a program that reads from the user a simple arithmetic expression using + and -, like 3 + 4 - 7 + 2 - 4 = and prints out the value of the expression. ***************************************************/ #include <iostream> using namespace std; int main() { cout << "Enter an expression: "; // Initialize total to 0 int total, k; char op; total = 0; op = '+'; // Loop while(op != '=') { // read next value cin >> k; // add or subtract value from total if (op == '+') total = total + k; else total = total - k; // read next op cin >> op; } // Write result cout << total << endl; return 0; }