Answer:

The program will print:

0

This is because MILE and MILE# are two different names, for two different variables. MILE# was first used in the PRINT statement, so that is when memory was found for it. It was initialized to zero, so it held a zero when the division MILE# / 12.5 was done.

Several Variables in a Program

A program may use many variables. Variables are useful for storing the intermediate parts of a calculation. Here is a different solution to the program you saw in chapter two:

Problem: Calculate the number of 8 ounce glasses of grape soda consumed if a 5 gallon keg of grape soda has 1.5 gallons still left in it. (There are 128 fluid ounces per gallon.)

' Glasses of Grape soda
' 
LET KEGSIZE = 5                            ' statement 1
LET LEFTOVER = 1.5                         ' statement 2
LET GALLONS = KEGSIZE - LEFTOVER           ' statement 3
LET OUNCES = GALLONS * 128                 ' statement 4
PRINT "glasses of soda =", OUNCES / 8      ' statement 5
END

Remember the idea of sequential execution. The statements of this program will execute one by one in order starting with the first statement.

In statement 1, the variable KEGSIZE is used for the first time, so memory is found for it. The LET puts a 5 in that memory. Here is what computer main memory looks like after statement 1 has executed.

KEGSIZE
5

Now statement 2 executes. Memory is found for the variable LEFTOVER and the value 1.5 is saved in it:

KEGSIZE
5
LEFTOVER
1.5

Statement 3 is more complicated.

LET GALLONS = KEGSIZE - LEFTOVER           ' statement 3

This statement does several things:

  1. Finds memory for the variable GALLONS
  2. Looks in KEGSIZE to get the value 5
  3. Looks in LEFTOVER to get the value 1.5
  4. Calculates 5 - 1.5
  5. Puts the result 3.5 in GALLONS

Remember that using the variables KEGSIZE and LEFTOVER in statement 3 does not change them. After statement 3 has executed, main memory looks like:

KEGSIZE
5
LEFTOVER
1.5
GALLONS
3.5

When statement 3 is finished, statement 4 executes.

QUESTION 12:

What 4 things does statement 4 do?

LET OUNCES = GALLONS * 128                 ' statement 4