A
Angie
I have a program that needs to read information from a file. This
information contains a name, a difficulty level and 9 scores.
The problem I am having is that my while loop isn't looping. It's only
reading the first full line of the file. Any suggestions?
Thanks in advance!
Angie
int main()
{
// declare variables
int SIZE;
double difficulty, score, total_score;
string name;
ifstream infile;
infile.open("MP6dive.dat");
if (!infile)
{
cout << "Trouble opening data file\n" ;
return 1;
}
infile >> SIZE;
infile >> name >> difficulty;
total_score = 0;
while(infile)
{
cout << name << setw(8) << difficulty << setw(7);
int i;
for(i=0; i <= JUDGES; i++)
{
infile >> score;
cout << score << " ";
total_score = score + total_score;
}
double final_score = total_score * difficulty;
cout << final_score << endl;
infile >> name >> difficulty;
}
infile.close();
return 0;
} // end main
information contains a name, a difficulty level and 9 scores.
The problem I am having is that my while loop isn't looping. It's only
reading the first full line of the file. Any suggestions?
Thanks in advance!
Angie
int main()
{
// declare variables
int SIZE;
double difficulty, score, total_score;
string name;
ifstream infile;
infile.open("MP6dive.dat");
if (!infile)
{
cout << "Trouble opening data file\n" ;
return 1;
}
infile >> SIZE;
infile >> name >> difficulty;
total_score = 0;
while(infile)
{
cout << name << setw(8) << difficulty << setw(7);
int i;
for(i=0; i <= JUDGES; i++)
{
infile >> score;
cout << score << " ";
total_score = score + total_score;
}
double final_score = total_score * difficulty;
cout << final_score << endl;
infile >> name >> difficulty;
}
infile.close();
return 0;
} // end main