How can I modify below code to allow the user to enter a weight for each grade in addition to entering number of students, name of student and amount of exams?
How can I modify below code to allow the user to enter a weight for
each grade in addition to entering number of students, name of student and amount of exams?
// C code
// This program will calculate the average of an undefined number
// of exams for an undefined number of students.
// Developer: F. Smith
// Date: June 24, 2020
#include <stdio.h>
int main(void) {
// variable declarations:
char name [100];
float sum, grade, average;
int students, grades, exams, studentquantity;
// Prompt user to input number of students
printf(“Please enter number of students: \n”);
scanf(“%d”, &studentquantity);
// loop through students
for (students = 0; students < studentquantity; students++) {
// Prompt user to input number of grades to process
printf(“Please enter number of grades for student (%d): “,(students+1));
scanf(“%d”, &grades);
sum = 0;
printf(“Enter Student name: “);
scanf (“%s”, name);
for (exams = 0; exams < grades; exams++) {
// float uses %f, double uses %lf
printf(“Enter grade %d: “,(exams+1));
scanf (“%f”, &grade);
sum = sum + grade;
} // end for each exam
average = sum / grades;
printf (“Average for %s is %.2f\n”, name, average);
printf(“\n\n”);
} // end for each student
printf(“… Bye …\n”);
return 0;
} // end main