Wednesday, 10 December 2014

GUESS A NUMBER USING IF_ELSE

GUESS A NUMBER

Now that we know all there is to know about random numbers, it is time to try some in a program. This first program creates a number in the range of 1 to 100. Then you get to guess the number. The computer will provide hints.
10  REM *********************************************************
20  REM *  GUESS1                                              *
30  REM *  Guess a random number selected by a BASIC program    *
40  REM *********************************************************
50  RANDOMIZE TIMER
60  NUMBER% = INT(1 + RND * 100)
70  CLS
80  PRINT "Guess a number in the range 1 and 100"
90  INPUT GUESS%
100 IF GUESS% = NUMBER% THEN GOTO 140
110 IF GUESS% > NUMBER% THEN PRINT "Too High!  Try Again"
120 IF GUESS% < NUMBER% THEN PRINT "Too Low!  Try Again"
130 GOTO 90
140 PRINT "Very Good!  You Guessed the Number."
150 END

No comments:

Post a Comment