Write a program that performs as a very simple calculator.
The program takes an operation followed by a series of
operands, and calculates and outputs the result.
Each expression is terminated by a semicolon (;).
The program is stopped by a "quit" command.
For example, input could be + 100 3.13 4;
* 5 537.4;
- 10 1 2 3 4;
quit
Read the operands as values of type double.
Implement calculation for operations + and *
with their obvious meanings.
Note that the minus operation (-) subtracts each consecutive number
from the current result, cumulatively.
(E.g., the last expression above gives the result zero.)
Similar semantics applies for division (/).
Compile and run your program.
Hint. We can use the stream operation clear()
to reset any IO error flags so that reading can again continue.