It would help if you indicated which function your having problems with.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
I would try something like below
double studentAverage(const std::vector<struct Student> & vec, int student_index_postion)
{
double average = 0.0;
unsigned long count = 0;
/*loop through exam scores*/
return average/count;
}
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
I have to ask, are you taking the average of each student or are you taking the average of the group of students?
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
Well here's a gimme
double studentAverage(const std::vector<struct Student> & vec, int student_index_postion)
{
double average = 0.0;
unsigned long count = 0;
for (unsigned long i = 0; i < vec[student_index_postion].exams.size(); ++i)
{
++count;
average += vec[student_index_postion].exams[i];
}
return average/count;
}
This will calculate the average of the student at student_index_postion in the vector.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0