Creating columns from a text file

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.

My program is:

#include <iostream>
#include <fstream>
#include <cfloat>
#include <iomanip>

using namespace std;

int main ()
{

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++ )
{

scoretotal = 0; // Initializer for nested loop

for ( testcounter = 0; testcounter < howmanyscores; testcounter++ )
{
inData >> currentscore;

scoretotal = scoretotal + currentscore; // Start of finding the average
}

// Average each student's test scores
if ( testcounter != 0 )
average = ( scoretotal ) / ( howmanyscores );


// Output student names and their scores in columns as well as avergaes
cout << left << studentname << setw(10) << average << endl;

// Pull out the next line
inData >> studentname;

} // End of student record processing

// Close opened file
inData.close ();

// Exit
return 0;
}
Any help would be greatly appreciated.
closed account (zvRX92yv)
'\t'
I am not sure what '\t' means? Could you please explain that?
By using '\t' (tab) rather than ' ' (space) you can line up columns
Topic archived. No new replies allowed.