#### PASCAL - Input Student Grades (Correcting loops)

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:

{\$mode objfpc}{\$H+}

uses
{\$ENDIF}{\$ENDIF}
Classes
{ you can add units after this };

{\$R *.res}

var //Setting the variable of the program.
x,y,v: integer;
z: integer;
sum: real;
average: real;
name:string;
id:string;

write('Name of Student: ');
write('Student ID: ');
writeln;

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

//1.Starting For loop to insert the values.
for x:= 1 to z do
begin

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

//2.Setting sum to 0. Condition stated if any number is equal or less than 100.
sum := 0;
begin
for v:= 1 to z do //For loop to start sum of grades.
begin
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');
halt;
end;
end;

//1.Setting sum to 0. Condition stated if any number is equal or less than 100.
sum := 0;
begin
for y:= 1 to z do //For loop to start sum of grades.
begin
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');