Write a program that asks the user for two numbers, then outputs the sum of these numbers. For example, if the user inputs 5
and 4
, the output should be 9
.
Extend your program to additionally ask the user for a basic arithmetic operator. The output should then be the result of the operation on the two numbers. For example, if the user inputs 5
, 4
, and -
, the output should be 1
.
Consider what the program does when you give it an unknown operator or other bad input. Then extend your program to accept three more uncommon arithmetic operators:
Name | Symbol |
---|---|
Modulus | % |
Quotient | // |
Exponent | ** |
See if you can reverse engineer what these operators do by testing your program with different inputs to determine a pattern.