Line 50 introduces TIME, which gives the value of the computer's internal

clock. TIME counts in hundredths of a second from the moment the computer is

switched on, or from when it is reset. Line 50 sets TIME back to zero, so that it

can be used to count the minute allowed for questions.

The variable answer is used to count the number of answers given, and is

initially set to zero by line 60. The loop runs from 70 to 130, and repeatedly asks

random multiplication questions until TIME is >= (greater than or equal to)

6000 hundredths of a second, one minute.

The program has one big flaw -- unlike Magnus Magnusson, it doesn't check the

answers! You will find out how to extend the program to do that in the next

section, so you might like to save the program before you continue.

Making choices

You have already seen that the computer can obey a series of instructions, or

repeat instructions a number of times. It can also choose whether to obey an

instruction or not:

10 MODE 7

20 PROCinput_age

30 END

40 DEFPR0Cinput_age

50 INPUT"How old are you " ,age

60 IF age<18 THEN PRINT'''So you can't vote in elections."

70 ENDPROC

RUN the program a few times, inputting different ages. In line 60, the

computer checks the statement after the IF, and if it is true, it executes the

instructions after the THEN. If the statement is false, the computer ignores the

rest of the IF...THEN and carries on to the next line.

Now add these lines to the program and run it several times, so that you are

sure you understand how IF ...THEN works:

63 IF age=21 THEN PRINT'"You are the same age as me!"

66 IF age<65 THEN PRINT '"You are below retiring age. "

The quiz program can now be extended so that it checks your answers. The new

lines are 65, 115 and 145:

10 MODE 7

20 PR0Cquiz

30 END

40 DEFPR0Cquiz

50 TIME=0

60 answers=0

C 41