12
SUM
starts out at 0, then the user enters "12", so:
SUM
Now say the program continues with the next three statements, and that the user enters "6":
' Ask the user for numbers. ' Add them up, print the sum. ' LET SUM = 0 ' Clear the sum ' PRINT "Enter a number" ' First number INPUT NUMBER ' User enters first number LET SUM = SUM + NUMBER ' increase the SUM ' PRINT "Enter a number" ' Second number INPUT NUMBER ' Second INPUT Statement LET SUM = SUM + NUMBER ' Second NUMBER added to SUM ' PRINT "Enter a number" ' Third number INPUT NUMBER LET SUM = SUM + NUMBER ' PRINT "The total is:", SUM ' At this point, SUM is the total of all numbers ' END
The second INPUT
statement will get the six and put it
in NUMBER
, replacing whatever was there before.
Now the next LET
statement:
SUM
The variables NUMBER
and SUM
are changed by these statements.
NUMBER
holds the new number input by the user.
Then
SUM
is changed to the new total.
Will NUMBER
and SUM
change
when the third number is read in?