I am having a bit of trouble with my last program I have to write. What I am asked to do is given a text file with students information, I am to output each student and then their test scores and the average of all of the them. For instance my input text file might look something like this:
4 5
Adams 97 29 100 88
Brown 99 88 77 66
Carter 94 55 66 77
Davis 0 22 77 88
Wilson 77 55 88 55
The top two numbers indicate how many test scores the program should expect and then how many students. It should be output to look something like this:
Adams 97 29 100 88 78.5
Brown 99 88 77 66 82.5
Carter 94 55 66 77 73.0
Davis 0 22 77 88 46.8
Wilson 77 55 88 55 68.8
-----------------------------------------
Averages 73.4 49.8 81.6 74.8
My program right now will read the students and then their average test scores. The part I am missing is getting it to print out the individual scores and then the class average for each one of tests.
ifstream inData; // Opens text file
string fileName; // Value for stating file did not open properly
int numstudents; // Student count
int howmanyscores; // Number of student's test scores
float scoretotal; // Before average total of a student's test scores
string studentname; // Student's last name read in
float average; // Average of test scores
int counter; // How many students to be read in
int testcounter; // How many student test scores to be read in
float currentscore; // Value being currently being read
string student;
// Open text file
inData.open ( "studdata.txt" );
if (!inData)
{
cout << fileName << " was not found. Ending program!";
return 1;
}
// Starts reading how many scores then students to expect
inData >> howmanyscores >> numstudents;
inData >> studentname;
// Beginning of nested for loop
for ( counter = 0; counter < numstudents; counter++ )
{