This calculator program evaluates mathematical expressions by following the PEMDAS order of operations.
It utilizes the Shunting Yard algorithm to convert Infix notation 4.2+18/(9-3)
to Reverse Polish notation 4.2 18 9 3 - / +
before solving.
- Parentheses:
(
,)
- Operators:
^
(exponentiation)*
(multiplication)/
(division)+
(addition)-
(subtraction)
go-cli-calc 2+2*2
OUTPUT: 6
go-cli-calc "4.2 + 18 / (9 - 3)"
OUTPUT: 7.2
go-cli-calc "(1-.5)+2*9+2"
OUTPUT: 20.5
- Whitespace between numbers and operators will not affect the calculation
- You may be able to omit the quotes "" if there is no white space between the numbers and operators
- Can't do
-(2+2)