Write a program, which will act as a simple four-function calculator. That is it
ID: 3652623 • Letter: W
Question
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.Modify above such that you use functions for each math calculation (Add, Subtract, Multiply, and Divide). Pass in parameters to each function for the values to use and the functions will return the result. Use a function to read in the numbers involved. These numbers will be doubles. Also write a function that reads in the operator and returns a boolean
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; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.