Turing 012 — Order of Operation

Remember from math class that 3 + 2 X 5 = 13, not 25. The same holds true for Turing.

Even though Turing will calculate algebraic equations properly, it is good programming practice to group items into their intended order of operation by surrounding them with parentheses (round brackets). For example, the above equation, written with a Turing put statement, is better written as:

put 3 + (2 * 5)

A more complex equation may be written as:

put 12 + ( ( 4 - 6 ) / 3 )

Things to remembers:

    • Turing uses '*' for multiplication, not 'x'

    • Turing uses '**' for exponentiation

    • Turing only uses parentheses (round brackets), not square brackets

    • Brackets can be nested (inside each other), and it is strongly encouraged if it makes the statement clearer

    • Assignment

Write a program that prints the equivalent of each of the following algebraic statements to the screen:

    • 2 + 4 x 5

    • 2 x 6 - 4/2

    • 8 + 2

    • (4+9/3)

    • 3[(4+12)-2(3-1)]

    • 23 + 42 - 6/3

Write each Turing statement so the output looks like the following:

2 + 4 x 5 = 22

...where "22" is calculated with your programmed formula.

Save as "012.t".