This is my program 'program_Student_Grades'. What this program does is that it displays out the I.D. and Average of the student and states whether he/she Passed or Failed. The program should not accept numbers that are higher than 100 or less than 1. It has an array that has a maximum input of 10. The problem is that if the number is higher or lower than the required amount I can only instruct it to remove all of the values within the array and instruct the user to retype the values. Secondly, it can only be done once, because if it is done twice, the program will ask the user to close the program. What I want to figure out is how to remove only the value that meets the conditions and how to make this check an infinite amount of times (no matter how many times the user makes the error).

Here's the code:

program_Student_Grades;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };

{$R *.res}

var //Setting the variable of the program.
grades: array[1..10] of real;
x,y,v: integer;
z: integer;
sum: real;
average: real;
name:string;
id:string;

write('Name of Student: ');
readln(name);
write('Student ID: ');
readln(id);
writeln;

write('Enter amount of grades desired: ');
readln(z);
writeln;
writeln('Enter grades: ');
writeln;

//1.Starting For loop to insert the values.
for x:= 1 to z do
begin
readln(grades[x]);

//2.Condition given so that the number doesn't cross >100 or <1.
if (grades[x] > 100) OR (grades[x] < 1) then
begin
grades[x]:=0;
writeln('ERROR: INVALID NUMBER! PLEASE ENTRE A NEW SET OF NUMBERS!');
for y := 1 to z do
begin
readln(grades[y]);
if (grades[y] > 100) OR (grades[y] < 1) then
begin
writeln('ERROR: INVALID NUMBER! PLEASE PRESS ENTRE TO STOP THE PROGRAM!');
readln();
halt;
end;
end;

//2.Setting sum to 0. Condition stated if any number is equal or less than 100.
sum := 0;
if grades[y] <= 100 then
begin
for v:= 1 to z do //For loop to start sum of grades.
begin
sum := sum + grades[v];
end;
end;

//Averaging the Sum.
average := sum/z;

writeln; // Conditions that state the name, id, and whether the student passed or failed.
if average >= 70 then
begin
writeln('The student ',name,' of id number ',id,' has PASSED with an average of ',average:0:2,'%.');
end
else if average < 70 then
begin
writeln('The student ',name,' of ID number ',id,' has FAILED with an average of ',average:0:2,'%.');
end;

writeln;
writeln;
writeln('Press Entre to Quit');
readln();
halt;
end;
end;

//1.Setting sum to 0. Condition stated if any number is equal or less than 100.
sum := 0;
if (grades[x] <= 100) or (grades[x] >=1) then
begin
for y:= 1 to z do //For loop to start sum of grades.
begin
sum := sum + grades[y];
end;
end;

//Averaging the Sum.
average := sum/z;

writeln; // Conditions that state the name, id, and whether the student passed or failed.
if average >= 70 then
begin
writeln('The student ',name,' of id number ',id,' has PASSED with an average of ',average:0:2,'%.');
end
else if average < 70 then
begin
writeln('The student ',name,' of ID number ',id,' has FAILED with an average of ',average:0:2,'%.');
end;

writeln;
writeln;
writeln('Press Entre to Quit');
readln();

end.