Microsoft Small Basic

Program Listing: JHR073
'A text based Guessing game!

'Initialize the game and determine number to be guessed
numToGuess = Math.GetRandomNumber(99)
numOfGuesses = 0


guesslabel:
'Reset guess
guess = ""
'Ask for input
TextWindow.WriteLine("Guess a number between 1 and 100!")
guess = TextWindow.Read()

'If guess is outside of range, tell user to guess again and add a guess to the counter
If(guess < 0 or guess > 100) Then
TextWindow.WriteLine("Choose a number between 1 and 100, silly!")
'Add 1 to guess counter
numOfGuesses = numOfGuesses + 1
Goto guesslabel
EndIf

'If guess is larger than numToGuess, Then tell user and add a guess, then go back to guessing.
If(guess > numToGuess) Then
TextWindow.WriteLine("That number is too large.")
numOfGuesses = numOfGuesses + 1
Goto guesslabel
EndIf

'If guess is smaller than numToGuess, Then tell user and add a guess, then go back to guessing.
If(guess < numToGuess) Then
TextWindow.WriteLine("That number is too small.")
numOfGuesses = numOfGuesses + 1
Goto guesslabel
EndIf

'You got it right! :D
If(guess = numToGuess) Then
TextWindow.WriteLine("You guessed the number " + numToGuess + " in " + numOfGuesses + " tries!")
Program.Delay(5000)
Program.End()
EndIf