I have a class named Student
, where I have the value of their grade as well as the value of the average grade.
I need to find the Student whose grade is closest to the average.
I have this:
void close (student s, int n){
int i, sum=0, averageGrade = 1;
for(i=0; i<n; i++)
sum = sum + s.GetAverage();
averageGrade = sum / n;
As an example, let's say that the average grade within all the student is 7.1. My task is to find the nearest grade of a single student that is closest to that value. Let's say John has an average grade of 7.2, Jim has 7.4 and Michael has 8.1. I need to find a way of finding the nearest value of the average grade between students and print their details. If multiple students are closest, I only need to find one student.