Getline not working in Looping statement....grrr...

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;
}

Num_Stu++;
Avg = Total_TS/Num_T;
Total_Avg+=Avg;

if ( Avg > 90.0 )
Grade = 'A';
else if ( Avg <= 90.0 && Avg > 80.0)
Grade = 'B';
else if ( Avg <= 80.0 && Avg >= 67.5)
Grade = 'C';
else if ( Avg <= 67.5 && Avg > 55)
Grade = 'D';
else
Grade = 'F';

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?

Thanks!
Last edited on
Did you get this working?
Topic archived. No new replies allowed.