Hey guys i am writing a program that reads in data from a file and stores it in a struct and i have a couple problems. The text file looks like:
Azrin, Neil 2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6 Babbage, Charles 2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5
the first number in the line is the difficulty level and the next 7 numbers are scores, goes on for 24 different names.
My program will print all the divers names followed by the difficulty levels. Then it will only print the first score for diver # 1, not all of the scores.
also, for diver #2's scores it prints out the second score (3rd number in line) and not the first score (2nd number in line). and so on for each diver.
how can i make it so it will read and print all of the scores for each diver?
ive been working on this for hours so any help is much appreciated!
my code:
for (lcv = 0; lcv < NUM_NAMES; lcv++) //reads in all of the data
{
getline(inFile, diveList[lcv].diversName);
inFile >> diveList[lcv].diff;
for (count = 0; count < NUM_SCORES; count++)
{
inFile >> diveList[lcv].scores[count]; //the problem may be here on down below where i print out the data... im not sure
}
inFile.ignore(200, '\n');
}
printTableOne (diveList);
void printTableOne (const diverList diveList)
{
int lcv;
int count = 0;
cout << "The number of divers for round 1 is: " << NUM_NAMES << endl << endl;
for (lcv = 0; lcv < NUM_NAMES; lcv++)
{
cout << "Diver #" << lcv << endl;
cout << setprecision(1) << fixed << endl;
cout << "NAME: " << diveList[lcv].diversName << endl;
cout << "DIFFICULTY LEVEL: " << diveList[lcv].diff << endl;
cout << "SCORES: " << diveList[lcv].scores[lcv] << endl; //problem here??
cout << endl << endl;
}