Code Wars II
Danger Level: Black
}Arithmetic Expression Evaluation~
Point Value: 11
Write a program to evaluate numerical
expressions that include addition, subtraction, multiplication, and division.
You will need to use proper operator precedence and parenthetical grouping.
Each line of the input file PROB14.IN is an expression to be evaluated. The expression syntax is identical to C, except all numbers are real (float) by default. The program should be able to handle up to 16 nested parenthetical groups. Here are some example lines from an input file:
3.2 + 7.091 * (-19.4 - 6.3)
8.4 * 19.6)
5.6 + ((32 / (71.3 - 9)
The program should numerically evaluate the expression and print the result to PROB14.OUT, the output file. If the program detects a group of incorrect parentheses then it must display the proper error message (only the first error if there are more than one). Here are the output lines for the above input:
error: unexpected )
error: unmatched (