Commodore 64 User Manual page 61

Hide thumbs Also See for 64:
Table of Contents

Advertisement

trates a good use of random numbers, but also introduces some addi-
tional programming theory.
In running this program, a random number, NM, will be generated.
NEW
1 REM NUMBER GUESSING GAME
2 PRINT "{CLR/HOME)"
` INDICATES NO
SPACE AFTER
QUOTATION MAR
5 INPUT "ENTER UPPER LIMIT FOR GUESS ".LI
10 NM = INT(LI*RND(1))+1
15 CN = 0
20 PRINT "I'VE GOT THE NUMBER.":PRINT
30 INPUT "WHAT'S YOUR GUESS".: GU
35 CN = CN + 1
40 IF GU > NM THEN PRINT "MY NUMBER IS
LOWER": PRINT : GOTO 30
50 IF GU < NM THEN PRINT "MY NUMBER IS
HIGHER": PRINT : GOTO 30
60 PRINT "GREAT! YOU GOT MY NUMBER"
65 PRINT "IN ONLY ": CN :"GUESSES.":PRINT
70 PRINT "DO YOU WANT TO TRY ANOTHER (Y/N?":
80 GET AN$ :
IF AN$="" THEN 80
90 IF RN$ = "Y" THEN 2
100 IF AN$ C? "N" THEN 70
110 END
You can specify how large the number will be at the start of the pro-
gram. Then, it's up to you to guess what the number is.
A sample run follows along with an explanation.
ENTER UPPER LIMIT FOR GUESS?
I'VE GOT THE NUMBER..
WHAT'S YOUR GUESS 7 15
MY NUMBER IS HIGHER.
WHAT'S YOUR GUESS ? 20
MY NUMBER. IS LOWER.
WHAT ' S YOUR GUESS ? 19
GREAT ! YOU GOT MY NUMBER
IN ONLY 3 GUESSES.
DO YOU J WANT TO TRY ANOTHER. (Y/N`-
51

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Commodore 64

Table of Contents