string position; // position played
int uniform; // uniform number
int games; // number of games played
int assists; // number of assists
int points; // number of points scored
int rebounds; // number of rebouns
cout << "Please enter name of player stats file" << endl;
cin >> filename;
infile >> team[n].uniform;
infile >> team[n].assists; // What to do here??
infile >> team[n].rebounds;
infile >> team[n].points;
cout << " UNIFORM # GAMES ASSISTS POINTS REBOUNDS" << endl;
cout << team[n].uniform << team[n].game << team[n].assists << team[n]points << team[n]rebounds << endl;
How can I read in the values and assign them to the correct variables?
There is a number of ways to solve this. What I'd do is read the whole file into a string, delete the spaces from the string, and read a number/char/number/char/etc.
This system relies on the fact that all the lines start with a number which is followed by a char-number pair. When you read the char use a switch statement to check if it is 'p', 'r', or 'a' and use that to assign the number to the corresponding variable
Remember to increment the index for 'tem' in the loop
I agree with Maeriden, read the file, remove spaces and then work with data.
I would consider writing 2 programs, or 2 functions, one will take the raw data and make it pretty, verify all the data is available, sorted and ready to output.
If one line has invalid numbers, letters, it would alert the user but continue to the next line.
The second would read the perfect file and manage stats, reports and output.
11, A#, P#, R#
The reason to do it this way is if your given multiple files for say 40 teams.
The first program sorts the data once, the second takes the polished data and spits out your report.
In the real world, you don't want to polish data more than once, but you might want to run multiple reports based on that data. no reason to clean it every time.