PRINT 16/4t2 III MllllI
the Commodore 128 responds with a 1 because it squares the 4
before it divides 16.
Using Parentheses to Define the Order of Operations
You can tell the Commodore 128 which mathematical operation
you want performed first by enclosing that operation in
parentheses in the PRINT command. For instance, in the first
example above, if you want to tell the computer to add before
dividing, type:
PRINT (4 + 6 )/2
This gives you the desired answer, 5.
If you want the computer to divide before squaring in the second
example, type:
PRINT (16/4)t2 RETURN
Now you have the expected answer, 16.
If you don't use parentheses, the computer performs the
calculations according to the above rules. When all operations in
a calculation have equal precedence, they are performed from
left to right. For example, type:
PRINT 4*5/10*6
Since the operations in this example are performed in order from
left to right, the result is 12 (4*5 = 20... 20/10 = 2 ...2*6 = 12). If
you want to divide 4*5 by 10*6 you type:
PRINT (4*5)/(10*6)
The answer is now .333333333.
CONSTANTS, VARIABLES AND STRINGS
Constants
Constants are numeric values that are permanent: that is, they do
not change in value over the course of an equation or program.
For example, the number 3 is a constant, as is any number. This
statement illustrates how your computer uses constants:
3-22
RETURN
nCTUnil