Guessing Game written in Turbo Pascal ver 5.5
Mike Leishman
Program guessing_game;
uses crt;
var
secret : Integer;
guess : Integer;
count_guess : Integer;
temperature : integer;
guessed : Boolean;
closeness : String;
Begin
clrscr;
guessed := false;
randomize;
secret := Random(100);
Writeln('A number guessing game. <1-10 HOT> <11-20 WARM> otherwise COLD');
Writeln;
Write('Guess the secret number <1-99> --> ');
Readln(guess);
count_guess := 1;
guessed := secret = guess;
while not guessed do
begin
temperature := abs(guess - secret);
case temperature of
1..10 : closeness := 'hot';
11..20: closeness := 'warm';
22..98: closeness := 'cold';
end; {case}
if guess > secret then
writeln('Too high and you are ', closeness);
if guess < secret then
writeln('Too low and you are ', closeness);
Write('Guess the secret number <1-99> --> ');
Readln(guess);
inc(count_guess);
guessed := secret = guess;
end;
Writeln('You guessed it!! It took you ',count_guess, ' guesses');
Writeln;
Write('Press enter to finish');
Readln;
end.
Comments (0)
You don't have permission to comment on this page.