Your task is to create an interpreter for a calculator. It has to parse commands like 5 + 5
and return the answer.
It has to be able to add, subtract, multiply, and divide. The interpreter only needs to accept two numbers (ex. 9 * 5
and 3 + 3
)
The interpreter will take input from a console/whatever, not a file.
Eval
isn't allowed
Examples:
Input: 5 * 5
Output: 25
Input: 8 / 2
Output: 4
Bonus
If you're really bored you can add these to the interpreter, if you'd like:
Simple mathematical functions like sqrt
.
Make the interpreter be able to accept more than two numbers (ex. 55 + 55
)
eval
allowed? 2) Can numbers be more than one digit? \$\endgroup\$8 / 3
print? \$\endgroup\$