Tutorial 2
The next commands you will need to know are:
SLEEP x
The variables
The SLEEP statement makes the computer pause. For example let's say
you wanted to make a program that would display a certain statement,
clear the screen, then display another statement (TRY IT!). All you
see is the second statement...Now try this program.
CLS
PRINT "HELLO"
SLEEP 1
CLS
PRINT "MY"
SLEEP 1
CLS
PRINT "FRIEND"
*The number after the SLEEP statement describes the number of seconds
to pause. If you simply type in SLEEP then the computer would
"sleep" until the user presses a key.*
Variables are used more often than you think. They describe constants
(numbers). Variables are good because they can be used to generate
random numbers, or increase or decrease during a loop (we will cover loops
later). Most of the items in this next program, you will not have seen,
but just enter it into QBasic, run it, and see what happens.
CLS
RANDOMIZE TIMER
X = INT(RND * 20) + 50
Y = 1
DO
PRINT "GUESS #"; Y
Input "", guess
IF guess > X THEN
PRINT "LESS THAN THAT."
END IF
IF guess < X THEN
PRINT "GREATER THAN THAT."
END IF
IF guess = X THEN
PRINT "YOU WIN!"
GOTO ENDING
END IF
Y = Y + 1
LOOP UNTIL Y > 20
ENDING:
PRINT "THANKS FOR PLAYING!"
* You can download that program by clicking here. You must
have winzip for this to work, though.*
This page was created by Chad R. (aka QBasicBoy)
Last modified 7-5-99