Simple calculator P35853


Statement
 

pdf   zip

html

Write a program to simulate a very simple calculator (with no brackets, nor priorities, nor associativeness of the operators).

Input

Input starts with the number of computations. All operands are real non-negative numbers written in the usual way. The operators of sum, substraction, product and division (‘+’, ‘-’, ‘*’ and ‘/’, respectively). An ‘=’ indicates the end of the current computation. Input can contain several spaces between the operators and the operands, but is syntactically correct.

Output

For each computation, print its result with 5 digits after the decimal point. Print “ERROR” for any computation that has any division by zero.

Public test cases
  • Input

    7
    4 =
    2+2=
    2 + 2.0 =
    3 + 2 * 2.5 - 19 =
    2 / 3 =
    55 + 666.666 + 1 / 0 + 9 * 9 = 
    1 + 1. + 1.0 * 9 =
    

    Output

    4.00000
    4.00000
    4.00000
    -6.50000
    0.66667
    ERROR
    27.00000
    
  • Information
    Author
    Jordi Petit
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++