Download Print this page

VTech PreComputer 2000 Manual page 23

Advertisement

Now is the time to throw all the operations together and it gets a bit
complicated.
After a winning baseball
game,
your 7 person team is awarded 3 cans of pop
for the game plus another
11
cans because you finished first in the league to
share among all players. How many cans does each player get?
Type this:
I
10
PRINT
3+11/7
Is it really evaluated from left to right?
Yes,
but was it the answer you were
expecting? If the answer came out to
4.57143,
the computer first divided
11
by
7
getting
1.57143
and then it added
3
to the result giving
4 .57143.
You probably
were expecting the answer to be
2
because
3+ 11
is
14,
then divided by
7
is
2.
You can see that expressions are not simply evaluated from left to right. It is
necessary to have an exact set of rules to follow
.
Here they are:
(
)
I\
*
I
+ -
things are parentheses (brackets)
highest
raising to a power
multiplication and division
addition and subtraction
lowest
The computer will always look at an expression in parentheses first and do the
things you put
there.
It could be an expression or more sets of brackets. Among
the expression, rais ing to a power is done first, followed by multiplication and
division from left to right
,
followed by addition and subtraction from left to right.
If you 're not sure how the computer will evaluate the
expression,
simply put
brackets around the expression you want done first. Remember the brackets must
always be in pairs, one right bracket for each left one
.
If you
don't,
then you
will get a "? SYNTAX
ERROR".
3. NUMERIC VARIABLES.
You have seen how you can use BASIC to print numbers and
messages.
You
can also give values to a BASIC program yourself. Then computer uses a letter
to stand for a value. This is called a
variable.
For example LET
D
=
609.
This
statement puts the value
609
into a box in memory called
"D".
Try this; type:
I
10 LET A=8
press
ENTER
The computer makes a box in memory and calls it
"A".
Into this box it puts the
number
8.
22

Advertisement

loading