I can't figure out why the following code doesn't output properly. It's supposed to read a name and grades into an an entry of an array of students. For some reason, there are phantom entries in between the real entries, as denoted by the lines in the output that don't have a name preceding the numbers.:
fin.open("data.txt");
for ( int i=0 ; getline(fin, info[i].name) && (i<SIZE) ; i++){
fin.clear();
fin >> info[i].quiz.gradeone;
fin >> info[i].quiz.gradetwo;
fin >> info[i].quiz.gradethree;
fin.clear();
numb++;
cout << info[i].name << info[i].quiz.gradeone << info[i].quiz.gradetwo
<< info[i].quiz.gradethree << endl;
}
fin.close();
Here's the data:
Jeramy Puleo
45 99 101
Liz Kershaw
55 70 35
Sherrill Dykes
88 94 100
Emmitt Auclair
89 94 88
Nana Bassler
22 55 88
And the (wrong) output:
Jeramy Puleo 45 99 101
0 32767 0
Liz Kershaw 55 70 35
0 0 0
Sherrill Dykes 88 94 100
0 0 0
Emmitt Auclair 89 94 88
0 0 0
Nana Bassler 22 55 88