Please help, got this code below that i need to add to a program im making and for some reason i cant work out why it doesnt work.
program dbase1;
uses Crt;
const fileName = 'C:\TEMP\NAMES.TXT';
maxRecords = 100;
var
name : array [1..maxRecords] of String;
address : array [1..maxRecords] of String;
numRecs : integer;
i,thisRec : integer;
inFile, outFile : TEXT;
ch : char;
begin
assign(inFile, fileName); reset(inFile);
numRecs:=0;
while not eof (inFile) do
begin
inc(numRecs);
readLn(inFile,name[numRecs]);
readLn(inFile,address[numRecs]);
end;
close(inFile);
repeat
writeLn;
writeLn;
writeLn;
writeLn('Database Program');
writeLn('----------------');
for i:=1 to numRecs do
writeLn(i,': ',name[i]);
writeLn;
repeat
write('Options: [a]dd, [u]pdate, [d]elete, [r]ead, [e]xit: ');
ReadLn(ch);
ch:=UpCase(ch);
until (ch='A') or (ch='U') or (ch='D') or (ch='R') or (ch='E');
writeLn;
if (ch='A') then
begin
if numRecs = maxRecords then
writeLn('Maximum number of records has been reached')
else
begin
numRecs:=numRecs+1;
write('Enter new name: ');
readLn(name[numRecs]);
write('Enter new address: ');
readLn(address[numRecs]);
end;
end;
if (ch='U') then
begin
write('Which record number do you wish to update? ');
readLn(thisRec);
if (thisRec<1) or (thisRec>numRecs) then
writeLn('Record number must be between 1 and ',numRecs)
else
begin
write('Enter name: ');
readLn(name[thisRec]);
write('Enter address: ');
readLn(address[thisRec]);
end;
end;
if (ch='D') then
begin
write('Which record number do you wish to delete? ');
readLn(thisRec);
if (thisRec<1) or (thisRec>numRecs) then
writeLn('Record number must be between 1 and ',numRecs)
else
begin
for i:=thisRec to numRecs - 1 do
begin
name[i] := name[i+1];
address[i] := address[i+1];
end;
numRecs:=numRecs-1;
end;
end;
if (ch='R') then
begin
write('Which record number do you wish to read? ');
readLn(thisRec);
if (thisRec<1) or (thisRec>numRecs) then
writeLn('Record number must be between 1 and ',numRecs)
else
begin
writeLn;
writeLn('Record no.',thisRec);
writeLn('-------------');
writeLn(' Name: ',name[thisRec]);
writeLn('Address: ',address[thisRec]);
end;
end;
until ch='E';
assign(outFile, fileName); rewrite(outFile);
for i:=1 to numRecs do
begin
writeLn(outFile,name[i]);
writeLn(outFile,address[i]);
end;
close(outFile);
end.