Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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