' Program to convert pounds sterling to dollars. ' The program keeps running until the user hits CONTROL-BREAK. DO PRINT "Enter price in pounds" INPUT PRICE PRINT "Price in dollars:", PRICE * 1.79 LOOP END
To make a small program repeat itself endlessly,
enclose it with DO
... LOOP
.
DO
and LOOP
are brackets that show
the beginning and end of the repeating part of a program.
Now, when the program is run, its output is:
Enter price in pounds ? 100 Price in dollars: 179 Enter price in pounds ? 50 Price in dollars: 89.5 Enter price in pounds ? 1 Price in dollars: 1.79 Enter price in pounds ?
(The INPUT
statement waits for you to type
something in, so the "?" prompt will stay there until you do.)
The conversion rate between pounds sterling and dollars changes every day. It would be nice if when you started the program at the beginning of the day that you could type in that day's conversion rate. Of course, you only want to do this once, when the program starts. Here is (nearly) what the new program looks like:
' Program to convert pounds sterling to dollars. ' First the user is asked for the number of dollars per pound. ' Then the program starts looping until the user hits CONTROL-BREAK. PRINT ______________________________ INPUT _______ DO PRINT "Enter price in pounds" INPUT PRICE PRINT "Price in dollars:", PRICE * RATE LOOP END
Complete the program by filling in the blanks.