Question: The program needs to stop running when I give it an invalid operator. Right now if I give it an invalid operator, it still asks

 The program needs to stop running when I give it an

The program needs to stop running when I give it an invalid operator. Right now if I give it an invalid operator, it still asks for two numbers, before letting me know that the operator isn't valid. How do I Fix that bug. Below is my program

#include #include

using namespace std;

int main() { char operation; double num1, num2, result;

cout > operation;

cout > num1; cout > num2;

switch (operation) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': result = num1 / num2; break; default: cout

cout

return 0; }

(10 points) Write a C++ program named hw3_1.cpp that emulates a simple calculator. First, your program prompts a user to enter a math operation to be performed. Then, it asks for two numbers to perform the operation on. If the user types in an operator that we haven't specified, you should print out an error message, as seen below. The following shows a sample execution of your program. When the instructor runs your program for grading, your program should display the result as below. Note that the boldfaced numbers are entered by a user. Here is another sample run, this one with an incorrect operator Welcome to the Hartnell calculator Enter operation to be performed (Note you must type in a +,, , or /) : \# Sorry, this isn't a valid operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!