Question: In C language In this assignment, you will design a simple calculator. The input to the program will have the format value operator value. Examples
In C language
In this assignment, you will design a simple calculator. The input to the program will have the format value operator value.
Examples include (but are not limited to):
Example Input 1
12.6 + 3.4
Example Input 2
123 % 2
Example Input 3
18 / 3
You should first read the two values and the operator. Then, compute the correct result and print it. The result should be an integer if both operands are integers. However, the result is always a double if the operation is a division. You will also have to report some additional information about the result, which is detailed under Additional Information.
Your calculator should support the following operators: +, -, *, /, %.
If an unknown operator is entered, output Unknown operator.
Input
123 ^ 2
Output
Unknown operator
Additional Information
Division
For division, you will have to check if it is a division by zero before you compute the result. In the event of a division by zero, rather than computing a result, simply print out:
Cannot divide by zero
Modulo
The modulus operator % only works on integers. You should check if the two values are integers before computing the result. If they are not both integers, print:
Modulo requires integers
It also has the same non-zero constraint as division. If there is a modulo by zero, print:
Modulo by zero
If both occur, print both out, with Modulo requires integers coming first.
Additional Information to Report
Once you have printed out the result, if the number is less than -1000 or greater than 1000, print:
Large number
Examples
Input
12.3 / 3.4
Output
3.617647
Input
100 * 20
Output
2000 Large number
Input
6 / 0
Output
Cannot divide by zero
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
