We will make the classic game Guess My Number. It is a very boring game to play, by today’s standards, but programing the game can be interesting.
Game Requirements
The program will prompt the user to select one of three games. The games are 1-10, 1-100, 1-1000. If the user does not enter the right selection, the program will display the selection again. Once the user selects the game, the program will randomize the number and prompt the user for a guess. The guess will be checked with the computer’s number. If the guess was not correct, the computer will prompt the user to guess higher or lower. If the guess was correct, the computer will display the number of times the user guessed, and the game will be over. The computer will prompt the user to play again. If the user does want to play again, the program will return to the game menu. If the user does not want to play again, the computer will quit the program.
Before we get to the code, there is a built-in function called UCASE$. UCASE$ converts the text to uppercase. UCASE$ is used to prevent the program from being case sensitive. The computer sees “A” differently than “a”. By converting the case, the user can enter both lower and uppercase answers and the computer will respond to the input the same way.
Code Download
QBT14.BAS
QB64 is a free download at www.qb64.com
QB64 Wiki & Manual is found at qb64.com/wiki.html
QBasic 1.1 comes with OldDOS. A zip file of OldDOS can be found at www.pcxt-micro.com/download.html
QBasic 1.1 needs DOSBox to run on Windows Vista and greater, Mac, and Linux.
DosBox is a free download at www.dosbox.com
Free QB64/QBasic Code
QBasic.Net - www.qbasic.net
Pete's QBasic Site - www.petesqbsite.com/index.php
QB45 - qb45.org
Phatcode - games.phatcode.net