我有一门课有 4 分的考试成绩。测试 1 - 测试 4。我想创建一个名为 mean 的函数,它将计算课程中每次考试的平均值并将其存储在 mean 数组中。但我似乎无法通过一个循环来完成这个:
class Cstudent
{
public:
string firstName, lastName;
int test1, test2, test3, test4;
float average;
};
/* Here is the problem, the next time i go through the loop, i want to store the sum of
test2 in to sum[1] after already storing the total in to sum[0] for test 1 */
float mean(Cstudent section[], int n)
{
int sum[NUMBEROFEXAMS];
float mean[NUMBEROFEXAMS];
for(int i = 0; i < NUMBEROFEXAMS; i++)
for(int j = 0; j < n; j++){
sum[i] += section[j].test1;
}
}