0
如何查找年齡等於或最接近平均年齡的學生年齡?我有一個功能,也排序。這是我迄今爲止使用C++的。查找等於或接近於使用向量一般的平均值C++
struct Student{
int age;
};
double getAveAge(vector<Student>&v)
{
int totalAge = 0;
int studentCount = v.size();
for(int x=0; x < studentCount; x++)
{
totalAge+= v[x].age;
}
return totalAge/studentCount;
}
double showMedian(vector<Student>v)
{
Student aStudent;
if (aStudent.age % 2)
{
}else{
}
}