Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ASSIGNMENT: Write a program, which will act as a simple four-function calculator

ID: 3638989 • Letter: A

Question

ASSIGNMENT:

Write a program, which will act as a simple four-function calculator. That is it will read a number, read an operator, read another number, then do the operation. The calculator works with integers and uses four functions: +, -, *, and /. After the first operation is completed, the program will read another operator and uses the result of the previous operation as the first value for the next operation. If the user enters a C the result is cleared and then the user starts entering a new number. If the user enters an X, the calculator is turned off. The various input values (i.e. numbers, operators, commands) will be followed by the ENTER key. Your program should prompt the user on what the user is to do. The commands C and X may be entered in place of an operator.

All numbers entered and displayed will be integer values.

NOTES:

The person using the calculator has a terrible time using a keyboard and may not always enter a valid operator. If this happens the program should ask for another operator.

Regardless of math operation attempted, the program must not die. If the math operation would cause a fatal error in your program you should check for it and issue an error message rather than attempting the operation.

Explanation / Answer

#include using namespace std; #include void main () { bool bValidOP; int number1; int number2; int answer; char Op; s: number1 = 0; number2 = 0; answer = 0; cout > number1; do { p: cout > Op; bValidOP = false; cout > number2; switch (Op) { case '+': answer = number1 + number2; break; case '-': answer = number1 - number2; break; case '*': answer = number1 * number2; break; case '/': answer = number1 / number2; break; case 'c': case 'C': bValidOP = false; cout