Atari 65XE Owner's Manual page 61

Hide thumbs Also See for 65XE:
Table of Contents

Advertisement

30 PRINT
40 PRINT "YOUR GUESS";
50 INPUT GUESS
60 PRINT
70 IF GUESS=SECRETNUM THEN PRINT "YOU GOT IT ! " : END
80 IF GUESS<SECRETNUM THEN PRINT "TOO LOW. TRY AGAIN. " :
GOTO 40
90 IF GUESS>SECRETNUM THEN PRINT "TOO HIGH.TRY
AGAIN.":GOTO 40
Lines 80 and 90 evaluate the guess as greater than or less than the
secret number. The PRINT statement provides a hint that the next
guess should be higher or lower. The GOTO commands in lines 80 and
90 create an infinite loop if you continue to guess incorrectly.
Ending the Program
The Number Quiz is programmed to stop only when you discover the
secret number. When you enter the correct answer, line 70 gives the
computer the instruction to end. END stops the program, and the
Ready prompt appears on your screen.
Trapping Errors
If you accidentally enter a letter instead of a number for GUESS, the
computer sends an Error message, and the program ends abruptly.
Make an intentional error by typing a letter key or pressing the
key only. To avoid ending the program, you can use a TRAP command
to trap the Error message. Add the lines below and run the program
again:
45 TRAP 100
100 PRINT:PRINT "PLEASE ENTER A NUMBER ONLY. "
110 GOTO 30
In line 45, the TRAP command tells the computer not to stop the
program when a mistake is entered and sends the computer to line
100. Line 100 tells the computer to print the directions for correcting
the mistake. Line 110 returns the computer to the place where it left
off. The TRAP statement always comes before the INPUT statement,
and it always contains the number of the line that will resolve the
problem.
Quiz Writing with IF-THEN
A program can easily provide hints when the correct answer is a
number, including a date. The following program uses IF-THEN
statements and the TRAP command to evaluate guesses:
56

Advertisement

Table of Contents
loading

Table of Contents