hi, im currently making a program where it records student's points, and teachers can update the points if they want. so now im on the procedure of update upon the existed points, but i've got this problem where after i updated one student's points, if i check back ,all my other student's records are gone! only left the one who updated correctly...i think i know what's the problem, because i used rewrite in the end of the procedure, but i just cant find another way of where i can successfully update one's data but keep others as well, please someone help!
it also be great if you can give me extra tips of how to improve my code, thanks!
Procedure AddPoints;
var newPoints, Sum, i, count: Integer;
TempStudent: TStudent;
begin
Clrscr;
Reset (StudentFile);
{Put all the persons in an array.}
NumStudents:=0;
while not eof(Studentfile) do
begin
inc(NumStudents); // make NumStudents =1;
read(Studentfile,Students[NumStudents]) // so it reads every stuents in 1 array;
end;
write('Enter the Student ID: ');
readln(id);
i:=1;
while (i<=NumStudents) and (Students[i].id<>id) do
inc(i);
{Display that person's detail from the array.}
if id = Students[i].id then
Writeln (' Please enter the new points');
Readln (newPoints);
Sum:= Students[i].points + newPoints;
tempStudent.points := Sum;
Students[i].points := TempStudent.points;
assign(StudentFile,'Student.dat');
rewrite(StudentFile);
Write (StudentFile, Students[i]);
Closefile(StudentFile);