I need to do an assignment where I make two programs, one to write a list of players in a team and their scores, the other to read and search the .dat file for specific players.
I have chosen to do this with an array but when I run my 1st program after I enter my first players score I get an exitcode 201
.
My Code:
Program TeamWrite;
Var FName : String;
UserFile : Text;
Players : array[1..10] of string;
Score : array[1..10] of integer;
List1: Integer;
List2: Integer;
BEGIN
FName := 'Team';
Assign(UserFile, 'C:\Team.dat');
Rewrite(UserFile);
FOR List1:= 1 to 10 DO
begin
Writeln('Enter players name and score separated by pressing enter.');
Readln(Players[List1]);
Readln(Score[List2]);
Writeln(UserFile, Players[List1]);
Writeln(UserFile, Score[List2]);
end;
close(UserFile);
End.
Please help!
Your variable
List2
is uninitialized, soScore[List2]
generates an "index out of bound" error. Actually you don't needList2
at all; just useList1
instead and your program should work.