Question: You will write a program that mimicks a simple calculator that can do adding, multiplication, or modulo of 2 integers. The program takes 3 arguments

 You will write a program that mimicks a simple calculator thatcan do adding, multiplication, or modulo of 2 integers. The program takes

You will write a program that mimicks a simple calculator that can do adding, multiplication, or modulo of 2 integers. The program takes 3 arguments at the command line: an integer, a character, and another integer. The character can be one of only 3 types:"+, X, or %. The program then returns either the sum, the product, or the modulo of the 2 integers. The program should be able to verify that 1) the user has exactly 3 arguments. 2) the operator used is one of the 3 allowed operators and nothing else. 3) when using modulo, the second integer is not zero (otherwise, you would divide by zero). For each of these conditions, the program should print out a specific error message (called USAGE messages) and exit. For each condition, the error message should be: 1) Number of arguments is incorrect. 2) Bad operation choice. 3) Cannot divide by zero. Hint: you have to use cerr instead of cout to output the usage messages. Do not use cerr for any other outputs the program makes. While cerr and cout are alike in that they direct values to standard output, we usually use cout for the standard output, but use cerr to show or report errors to the user and the system You may use the exit(1) statement when exiting from giving some of the error messages. The instructor will demonstrate the proper use of exit(1) and cerr in class on Tuesday

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!