CIS 254 Intro to Object Oriented Program Design

Project 4.3

Write a program that serves as a simple calculator. The program should ask the user for a number, an operator, and then a second number. The operator should be either '+', '-', '*', or '/'. The program should then report the answer to the problem. Use a switch statement, not an if statement. Note that "operator" is a reserved word in C++, so you cannot use it as a variable name.

Your program should prompt the user for each of the three inputs separately, on separate lines.

Use double variables so that your calculator can work with decimals. Round answers to 2 digits after the decimal point. Hint: in order to get the numbers to print with two digits after the decimal point, #include <iomanip> at the top of your program and use something like

cout << setprecision(2) << fixed << ....

Sample screen output:

Enter first number: 7.0
Enter an operator (+, -, *, or /): /
Enter second number: 3
The answer is 2.33