Programs to Debug: Number 6

We suggest that you inspect this program to see if you can spot the errors before attempting to compile it in Delphi or Lazarus. Make the necessary changes so that each program will compile and achieve the stated purpose. Our pages on common programming errors may help you.

program NumberGuess;
{$APPTYPE CONSOLE}
{The program should output the number of guesses needed to
determine the random number selected by the computer.
The program contains two deliberate errors.}
uses
  SysUtils;
var
  strGuess : string;
  ErrorCode, intGuess, GuessNum, Rand  : integer;
  Guessed : Boolean;
begin
  Guessed := False;
  GuessNum := 0;
  Randomize;
  Rand := Random(100);
  writeln('The computer has selected a number between 1 and 100 (inclusive).');
  writeln('See how many guesses you need.');
  writeln('The computer will let you know if your guess is correct, low or high.');
  repeat
    inc(GuessNum);
    repeat
      write('What is your guess number ',GuessNum,'? ');
      readln(strGuess);
      val(strGuess, intGuess, ErrorCode);
    until ErrorCode = 0;
    if intGuess = Rand then
      begin
        Guessed := True;
        writeln(Correct!);
        writeln('Number of guesses: ',GuessNum);
      end
    else
      if intGuess > Rand then
        begin
          writeln('Guess too high.');
        end
      else
        begin
          writeln('Guess too low.');
        end;
  until Guessed = True;
  readln;
end.
Programming - a skill for life!

Spot the deliberate errors