Higher or Lower

Purpose : QBasic TAFE Assessment

Programs : QBasic

Scripts: QBasic


A simple program that will randomly generate a number between 1 and 100 and then lets the user guess the number using a higher / Lower instruction within 7 guesses.

The Code:

[cc lang=”vb”]
CLS
REM **********************************************************
REM * *
REM * IAN BLOTT *
REM * *
REM * *
REM * CREATED ON 10/2/2005 *
REM * *
REM **********************************************************

PRINT “Enter a number between 1 and 100”
RANDOMIZE TIMER
x = INT(RND * 100 + 1)
y = 7
z = 0
DO WHILE z < 7 INPUT a IF a = x THEN PRINT "yes" z = 8 PRINT "You got it in "; c; " guess's" ELSE c = c + 1 b = 7 - c IF x > a THEN
PRINT “higher”
ELSE
PRINT “Lower”
END IF
IF b = 1 THEN
PRINT ” You only have 1 Guess left”
ELSE
IF b = 0 THEN
PRINT “You failed”
ELSE
PRINT “you have “; b; ” guess’s left”
END IF
END IF
z = z + 1
END IF
IF z = 7 THEN
PRINT “the number was “; x; ” you stooge”
END IF
LOOP
[/cc]