PROGRAM ClassGrade;
{ Program to compute class' grade point average using }
{ A = 4.0, B = 3.0, C = 2.0, D = 1.0 & F = 0.0 }
USES Crt;
VAR grade : char;
students, classSize, gradeValue : integer;
totalPoints : real;
BEGIN
ClrScr;
{ Initialize accumulator (running totals) variables }
classSize := 0;
totalPoints := 0;
gradeValue := 4;
{ First we loop fom 'A' to 'D' }
FOR grade := 'A' TO 'D' DO
BEGIN
write('How many ',grade,'s: ');
readln(students);
classSize := classSize + students;
totalPoints := totalPoints + (students * gradeValue);
{ For the next letter grade, the value is one less }
gradeValue := gradeValue - 1;
END;
{ Now deal with the Fs }
{ Since the F has a value of 0.0, we only need to how many were given }
write('How many Fs: ');
readln(students);
classSize := classSize + students;
writeln;
writeln('Class size: ', classSize);
{ Format the output to only 2 decimal digts }
writeln('Class average: ', (totalPoints / classSize):0:2);
END.