In QBasic, create a guessing game. You should have your program to generate a ra
ID: 3592661 • Letter: I
Question
In QBasic, create a guessing game. You should have your program to generate a random number from 1-100 (inclusive). Let the user guess a number from 1-100. The program should let the user guess until they get the correct number. After each input, the program should tell the user whether they guessed the correct number, or if they should guess higher or guess lower. While the user is entering guesses, the program should keep a count of the number of guesses that it takes to get the correct number. After the user guesses the correct number, the program should congratulate the user and tell them how many guesses it took them to get the correct number.
Explanation / Answer
DIM range AS INTEGER
DIM guess AS INTEGER
DIM numguess AS INTEGER
DIM magicnumber AS INTEGER
CLS
PRINT "---Guessing game---"
INPUT "Enter range (1-100): ", range
RANDOMIZE TIMER
magicnumber = INT(RND * range) + 1
numguess = 0
DO WHILE (guess <> magicnumber AND guess >= 0)
INPUT "Enter your guess, or -1 to exit: ", guess
numguess = numguess + 1
IF guess < magicnumber THEN PRINT "It is greater"
IF guess > magicnumber THEN PRINT "It is less"
LOOP
IF guess = magicnumber THEN PRINT "You got it in"; numguess; "tries."
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.