Programs to Debug: Number 10

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 ArrayEntry;
{This program should read at most 5 names into an
 array until END is entered and then output a list
 of the entered names.  There are two deliberate
 errors.}
{$APPTYPE CONSOLE}
{$R+}
uses
  SysUtils;
const
  MAX_NAMES = 5;
var
  Surnames : array[1..MAX_NAMES] of string;
  Name : string;
  Count : integer;
begin
  for Count := 1 To MAX_NAMES do
    begin
      Surnames[Count] := '';
    end;
  Count := 1;
  write('Enter the next name (END to finish) ');
  readln(Name);
  while (Count <= MAX_NAMES) and Name <> 'END' do
    begin
      Surnames[Count] := name;
      Count := Count + 1;
      if Count < MAX_NAMES + 1 then
        begin
          write('Enter the next name (END to finish) ');
          readln(Name);
        end;
     end;
  writeln
  writeln('The entered names are:');
  for Count := 0 to MAX_NAMES do
    begin
      if (Surnames[Count] <> '') then
        writeln(Surnames[Count]);
    end;
  readln;
end.
Programming - a skill for life!

Spot the deliberate errors