Programs to Debug: Number 7

We suggest that you inspect this program to see if you can spot the error 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 AdditionTest;
{$APPTYPE CONSOLE}
{The program should inform the user which sums are correct,
supply the correct answer if necessary, and give a score out of 3.
There is one deliberate logic error.}
uses
  SysUtils;
var
  strAnswer : string;
  ErrorCode, intAnswer, Score, Rand1, Rand2, Sum, QuestionNum  : integer;
begin
  Score := 0;
  Randomize;
  for QuestionNum := 1 to 3 do
    begin
      Rand1 := Random(100)+ 1;
      Rand2 := Random(100)+ 1;
      Sum := Rand1 + Rand2;
      repeat
        write('What is ',Rand1,' + ',Rand2,'? ');
        readln(strAnswer);
        val(strAnswer, intAnswer, ErrorCode);
      until ErrorCode = 0;
      if intAnswer <> Sum then
        writeln('You are wrong.  The sum is ',Sum)
      else
        writeln('Correct!');
        Score := Score + 1;
    end;
    writeln('You scored ',Score, ' out of 3.');
  readln;
end.
Programming - a skill for life!

Spot the deliberate errors