Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab4 simple calculator, anyone can help me with this C++ lab4 10:55 Objectives Using an if or switch statement Using a while loop In this
Lab4 simple calculator, anyone can help me with this C++ lab4
10:55 Objectives Using an if or switch statement Using a while loop In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as you want. You will be creating this program in You have the menu, the performance of the basic arithmetic operations (Addition, Subtraction, Multiplication, and Division). and the looping. You may want to get the switch menu working first, and then fill in the code for these four arithmetic three small sections Your program will keep a running total. It should print the subtotal out after each and every calculation. In addition, the total should be printed before the program quits. So with that being said, the program needs to define a data field, named total at the beginning of main and set it to zero. Part A: Designing the menu systenm Menu systems in C++(and other languages) are often represented as a switch statement. Design a switch statement that handles five cases and a default case . case 0-Exit case 1-Addition e case 2- Subtraction case 3-Multiplication . case 4- Division default-Error message Make sure to print out a list of options explaining to the user what each case does, like Enter 1 to add a number to total or "Enter 2 to subtract a number from total" This menu should appear before the switch statements. It is also vital to allow the user to input their choice of 0-4. Part Billing in the Cases At this point, you should have a working menu that does nothing. It is time to add code to each of the cases so that they will do the function you displayed to the user. Start by writing code inside of case 1 that will prompt the user to enter a single number. Since this case is for addition, you will want to make sure to add the number you entered to the running total Once this works, you should do the same for the other mathematical functions. Only substituting in the other three operation Part C: Repetition Allowing the user to select which function then input data is nice. But how often do you open the calculator and do just a single calculation? It would be a good idea to wrap your entire menu into some sort of structure that allows it to repeat more than a single time. If you were to use such a thing, how would you stop it? Part C is to surround your entire program thus far with a loop that allows it to be run more than once. It would also be a good idea to allow for exiting this loop. Be sure to Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started