You must write a program that evaluates a string that would be entered into an advanced calculator.
The program must accept input using stdin and output the correct answer. For languages that do no have functions to accept stdin, you may assume the functions readLine
and print
to handle these tasks.
Requirements:
- Does not use any kind of "eval" functions
- Can handle floating point and negative numbers
- Supports at least the +, -, *, /, and ^ operators
- Supports brackets and parenthesis for overriding the normal order
- Can handle input containing one or more spaces between the operators and numbers
- Evaluates the input using the standard order of operations
Test Cases
Input
10 - 3 + 2
Output
9
Input
8 + 6 / 3 - 7 + -5 / 2.5
Output
1
Input
4 + [ ( -3 + 5 ) * 3.5 ] ^ 2 - 12
Output
41
.0
at the end if they're integers? Also: how accurate does the calculator have to be (regarding floating point precision and such)? \$\endgroup\$.0
on the end. I'm not too sure about the precision, but more is better. \$\endgroup\$