30 PRINT
40 PRINT "YOUR GUESS";
50 INPUT GUESS
60 PRINT
70 IF GUESS=SECRETNUM THEN PRINT "YOU GOT IT ! " : E N D
80 IF G U E S S < S E C R E T N U M THEN PRINT "TOO LOW. TRY A G A I N . " :
GOTO 40
90 IF G U E S S > S E C R E T N U M THEN PRINT "TOO HIGH.TRY
A G A I N . " : G O T O 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 N U M B E R O N L Y . "
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
Summary of Contents for 65XE
Page 1: ...ATARI 65XE PERSONAL COMPUTER OWNER S MANUAL TM...
Page 3: ...ATARI 65XE PERSONAL COMPUTER TM...
Page 6: ...Part 1 GettingStarted 1...
Page 9: ...4...
Page 23: ...18...
Page 25: ...20...
Page 32: ...Part 2 Programming withATARI BASIC 27...
Page 33: ...28...
Page 59: ...54...
Page 69: ...64...
Page 82: ...Part3 Appendices 77...
Page 83: ...78...
Page 97: ...92...
Page 105: ...100...
Page 125: ...120...
Page 126: ...121 Index...
Page 127: ...122...
Page 134: ...ATARI 1987 Atari Corp All Rights Reserved Printed in Taiwan C072018 001 REV B K l 2 1987...
Page 135: ......