| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Guessing Game Turbo Pascal 5_5 M Leishman

Page history last edited by Mike Leishman 16 years, 10 months ago

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.