How could this code be modified to allow the user to enter more than three grades per student? #include int main(void) { // variable declarations: char name [100]; float sum, grade, average; int students, exams, numvalues; //set number “n” of students
How could this code be modified to allow the user to enter more than three grades per student?
#include <stdio.h>
int main(void) {
// variable declarations:
char name [100];
float sum, grade, average;
int students, exams, numvalues;
//set number “n” of students
printf(“How many students are you finding the average for?:\n”);
scanf(“%d”, &numvalues);
// loop through 5 students
for (students = 0; students < numvalues; students++) {
printf (“Enter 3 grades and student name: “);
sum = 0;
for (exams = 0; exams < 3; exams++) {
// float uses %f, double uses %lf
scanf (“%f”, &grade);
sum = sum + grade;
} // end for each exam
average = sum / 3;
scanf (“%s”, name);
printf (“Average for %s is %.2f\n”, name, average);
} // end for each student
printf(“… Bye …\n”);
return 0;
} // end main