Beginner's Programming Tutorial in QBasic

(Kiana) #1

Guessing game


The following is a simple guessing game:
CLS
start:
PRINT "Guess a number between 1 and 10: ";INPUT num
IF (num < 1 OR num > 10) THENPRINT "That is not between 1 and 10"
GOTO start
END IF
IF (num = 6) THEN
ELSEPRINT "Correct!!!"
PRINT "Try again"
PRINTGOTO start
END IF
Output (may be slightly different):
Guess a number between 1 and 10:? Try again 2
Guess a number between 1 and 10:? 7
Try again
Guess a number between 1 and 10:? Correct!!! 6


TIP: Notice the second PRINT statement under
PRINT "Try again". It adds a blank line
under Try again when the program is
executed.
Free download pdf