Problem #14

Code Wars II
Danger Level: Black



}Arithmetic Expression Evaluation~

Point Value: 11
 

Problem Statement

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.
 

Program Input

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)
(1.3+0.1*(4.3+7.4*19.3-72/(3.14+2.4*9.2)+96))/(64.3-13*(9-4/-3))
8.4 * 19.6)
5.6 + ((32 / (71.3 - 9)
 
 

Program Output

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:

-179.0387
-0.3616351112589
error: unexpected )
error: unmatched (