To do the average grade calculation for each of the students, your AvgGrade2 function should call AvgGrade1 for each element of the array.
So, you need to pass to AvgGrad2 the array, the number of students, and the number of tests. Use a loop in the function, sending each student in turn to the function that does the actual calculation.
Val
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
xyz should be an array of ClassList objects each of which has an array of test results in it. Each ClassList object stands for a single student. You want to calculate the average test result for each student withing xyz. So you need a nested loop, the outer one to keep track of which student in xyz and the inner one to keep track of individual test results.
double sum;
void AvgGrade2 (ClassList *xyz, int x, int y)
{
for(int stu = 0; stu < y; ++stu)
{
sum = 0.0;
for (int i = 0; i < x; i++)
{
sum += xyz[stu].TestGrades[stu];
}
xyz[i].Avg = sum / x;
}
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
sorry, should have been:
sum += xyz[stu].TestGrades[i];
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396