% Guess a secret number chosen by the computer game
% The computer randomly chooses a number between 1 and 99
% and the user attempts to guess the number using hints from the computer
randomize % Set up variables, randomizer, etc.
var secret_number,guess:int
var reply:string(1)
% Place a prompt on the screen to give instructions, etc.
put "See if you can guess the hidden number"
put "It is between 1 and 99 inclusive"
% Set up a loop to allow the person to play multiple times.
loop
var count:int:=0 % Declare variable to track number of guesses
put "Do you want to play? Answer y or n ".. % Muliple plays? Get user answer
get reply
exit when reply="n" % End the program when user chooses no
randint (secret_number, 1, 99)
% Loop to get the guesses, check and loop until guess and secret_number match.
loop
put "Enter your guess ","(any number between 1 and 99) "..
get guess
count:=count+1 % Counter to keep track of guesses
if guess < secret_number then
put "Your guess is low. Try a higher number."
elsif guess > secret_number then
put "Your guess is high. Try a lower number."
else
put "Congratulations!. You got the correct answer in ",count," guesses."
exit
end if
end loop
end loop