My question is about while loop statements. In this program it won't seem to read what is in my input. after the first name and set of scores. It just prints this inifinitely
Toots Sweet3 84.3 B
3 84.3 B
3 84.3 B
3 84.3 B
3 84.3 B
:
getline (fin, Class_Name);
getline (fin, Name);
while( !fin.eof())
{
fin >> Score;
while ( Score != -1 )
{
Num_T++;
Total_TS+=Score;
fin >> Score;
}
if ( Num_T == 0 )
{
fout <<left<<endl;
fout <<Name<<setw(25)<<" Error there were no scores for this student."<<endl;
}
else
{
fout <<setprecision(3)<<endl;
fout <<Name<<setw(15)<<Num_T<<setw(15)<<Avg<<setw(15)<<Grade<<setw(10)<<endl;
}
getline (fin, Name);
}
I think it may be because it can't read the Name correctly. The input file is exactly like this:
Introduction to Programming I
Toots Sweet
87 76 90 -1
Willy Nilly
73 63 64 70 -1
Phil O'Sophy
-1
Jill Quirk
90 80 70 -1
Perhaps I'm not telling my program to read the next line? Do I need to do that?