Here is your testing assignment. Follow these steps to fulfill the goals of the assignment.
(Note that this source code will be sent by e-mail)
/***********************************************************
Spring 1997 A grading program
Roger Hartley
This program reads a list of grades, and prints the number
of grades in each of the standard grading ranges: 90% and
above is A, 80-89% is B, 70-79% is C, 60-69% is D, and below
60% is F
***********************************************************/
#include <stdio.h>
float ReadGrade() {
float grade;
int n;
printf("Type a grade: ");
n = scanf("%f", &grade);
if (n == EOF) /* scanf read end of file */
return -1;
else
return grade;
}
void ProcessGrade(float g, int ga[]) {
int gradeIndex;
if (g >= 90.0)
gradeIndex = 0;
else if (g >= 80.0)
gradeIndex = 1;
else if (g >= 70.0)
gradeIndex = 2;
else if (g >= 60.0)
gradeIndex = 3;
else
gradeIndex = 4;
++ga[gradeIndex];
}
void printGrades(int ga[]) {
int gradeIndex;
char gradeLetter;
printf("The number of each grade input is:\n\n");
for (gradeIndex = 0; gradeIndex < 5; gradeIndex++) {
if (gradeIndex < 4)
gradeLetter = 'A' + gradeIndex;
else
gradeLetter = 'F';
printf("%c %d\n", gradeLetter, ga[gradeIndex]);
}
}
int main() {
float grade = 1;
int gradeArray[5] = {0};
while (grade > 0) {
grade = ReadGrade();
ProcessGrade(grade, gradeArray);
}
printGrades(gradeArray);
}