I am trying to use a function to calculate a grade average and store the letter grade into "letter". However, whenever I try to call the function, I get an error saying "no matching for call to "findAvg". I do not completely understand references and pointers. Is that the issue here? Any help and information is appreciated, thank you.
#include <iostream>
#include <fstream>
using namespace std;
class Student{
public:
double grades[4];
float avgGrade;
string letter;
string name;
};
void findAvg(Student f[]);
int main(){
Student students[3];
int i = 0;
fstream fin;
fin.open("input1.txt");
while(!fin.eof()){
fin >> students[i].name;
for (int j =0; j < 4;++j){
fin >> students[i].grades[j];
}
i += 1;
}
fin. close();
findAvg(students[3]);
cout << students[1].letter;
}
void findAvg(Student f[]){
for(int i = 0;i<3;++i){
f[i].avgGrade = ((f[i].grades[0] + f[i].grades[1] + f[i].grades[2] + f[i].grades[3]) /4);
if (f[i].avgGrade>=90){
f[i].letter = "A";
} else if (89>f[i].avgGrade && f[i].avgGrade<=80){
f[i].letter = "B";
} else if (79>f[i].avgGrade && f[i].avgGrade<=70){
f[i].letter = "C";
} else if (69>f[i].avgGrade && f[i].avgGrade<=60){
f[i].letter = "D";
} else {
f[i].letter = "F";
}
}
}
std::vectorfor dynamic arrays andstd::arrayfor fixed size. What do you think this line is doingfindAvg(students[3]);?avgGradeof89.5, then your code will assign that as an F.