Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions