' Average of three test grades ' PRINT "Average Test Grade:", (68 + 84 + 92) / 3 END
When the PRINT statement executes will do the arithmetic (first the addition, then the division).
(68 + 84 + 92) / 3 = 244 / 3 = 81.33333 -------------- do first
Then it will print to the monitor:
Average Test Grade: 81.33333
A common combination is to divide the sum of several numbers by the sum of several other numbers. In paper-and-pencil arithmetic this might look like:
12 - 8 + 4 ---------- 2 + 6
The big horizontal division line makes the grouping clear: the arithmetic above the line is done, then the arithmetic below the line is done, and then the two results are divided. In QBasic do this with TWO SETS of parentheses:
(12 - 8 + 4) / (2 + 6)
The insides of BOTH sets of ( )
must be done
before the division is performed.
So the above is done like:
(12 - 8 + 4) / (2 + 6) = 8 / (2 + 6) = 8 / 8 = 1 ------------ ------- first next
What will the following program write to the monitor:
' Division example ' PRINT (10 + 2) / (3 + 3) END