# Variations of a number guessing game.

One of my favorite games is the classic “Guess the Number” in which you try guessing a number and the computer tells you whether your guess is too high or too low. Here’s a VB Script version:

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter your guess.”, _
“Guess the Number”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
Wscript.Echo “Too high.”
elseif Cint(strGuess) < IntNumber then
Wscript.Echo "Too low."
end if

Loop

Wscript.Echo "You guessed it!"

I find myself playing this game whenever I’m in need of a quick break. Still, I try to see how I can vary the game and have come up with some pretty interesting variations. Here’s one that not only tells you whether your guess is too high or low, but it tells you how far off your guess is. With a little math, you can guess the correct number on the next try.

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter your guess.”, _
“Guess the Number”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
Wscript.Echo “Too high and off by ” & Cint(strGuess)-IntNumber & “.”
elseif Cint(strGuess) < IntNumber then
Wscript.Echo "Too low and off by " & Cint(strGuess)-IntNumber & "."
end if

Loop

Wscript.Echo "You guessed it!"

Finally, here’s a variation that caters to those in the shallow end of the gene pool. I call this one Guess the Number for Dummies. Here the computer makes every effort to tell you the answer and gives you a hard time if you put in a wrong guess.

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Wscript.Echo “HINT: The number I’m thinking of is “& intNumber & “.”

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter the number I’m thinking, which is ” & intNumber & “.”, _
“Guess the Number for Dummies”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
Wscript.Echo “NO! Too high! The answer is ” & IntNumber & “! Try again!”
elseif Cint(strGuess) < IntNumber then
Wscript.Echo "NO! Too low! The answer is " & IntNumber & "! Try again!"
end if

Loop

Wscript.Echo "You actually got it? How did that happen?"
Wscript.Echo "MORON!"

You have no idea how much fun I had making that one.