QBasic Tutorial 14 - Guess My Number Game - QB64



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




QBasic / QB64 Links



QB64 is a free download at www.qb64.org

QB64 Wiki & Manual is found at www.qb64.org/wiki/Main_Page

QBasic 1.1 is found within OldDOS.exe.
OldDos is a free download at download.microsoft.com/download/win95upg/tool_s/1.0/W95/EN-US/olddos.exe

On some web browsers, the Microsoft link does not work, because the download comes as an exe file. 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