Guessing Game

 
 

program Guess;

uses Types, QuickDraw, MiscTool;


var

  ans, rand, loop, score: Integer;


begin


  { Setup }


  graphics(640);

  setRandSeed(getTick);

  hidecursor;

  writeln('*** Guessing Game *** By: Ding Wen');

  writeln;


  { Set varibles }


  loop := 0;

  score := 110;

  rand := random mod 100 + 1;


  while loop <= 10 do begin

    loop := loop + 1;

    score := score - 10;


    { Ask question }


    writeln('Guess a number from 1 to 100.');

    readln(ans);


    { Check answer }


    if ans < rand then

      writeln('Too low.')

    else begin

      if ans > rand then

        writeln('Too High.')

      else begin

        if ans = rand then begin

          writeln('You Win!');

          writeln('You had ', loop, ' tries.');

          writeln('Good luck next time!');

          leave;

        end;

      end;

    end;

  end;


  { Write score }


  writeln('Here is your score:',score, '/100');

  readln;

end.

This program is a classic guessing game implemented for Apple IIGS.


It shows the understanding of various programming concepts like loop and decision making. It also shows how to use the system tick to do a better random number generation.