post the contents of the data file, or just a few lines if its too large. Your program is written to expect all student ids to be listed first, followed by all answers and lastly the total number correct for each student. But I doubt that is how they appear in the data file.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
where is the third column? Your program needs only one loop. maxcols is too small -- needs to be 1 more than the number of t/f test scores.
for (int c = 0; c<maxstudents; c++)
{
infile>>studentid[c] >> quiz[c];
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
-86, is that a compile-time error or runtime error?
1. make sure maxstudents is not greater than the number of lines in the data file. There are better (and easier) ways to read the file without knowing the number of lines beforehand, but get this working first and you can refine your program later.
2. The output line is incorrect. It should look like this:
cout<<quiz[r]<<"\t";
If you still have problems after making the changes, repost your program. But those should fix it, at least it did in my version that I don't intend to post :)
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
const int maxcols=4;
Count the number of t's and f's in one of those lines. How many did you count? Less than 4 or more than 4. maxcols needs to be a minimum of (number of t's and f's) + 1 for the character array's null-terminator.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
visually verify the data file is correct -- no blank lines and every line has the same format.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Please provide several lines from the file and how it is to be interpretted. I suspect you are setting up the arrays incorrectly.
For example, if the file looks like this:
ABC
BBA
CBB
then
char quiz[3][3];
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
infile >> quiz[i][j];
could be used to hold the entire contents of the file and maintain the relationships between lines, etc. Then if you assigned student number by index of number of the row of the array, you could output the student number and the scores of each student like this:
for(i = 0; ...)
cout << "student" << i << ;
for(j = 0; ...)
cout << quiz[i][j] << ' ';
cout << endl;
However, without knowing exactly how the file looks, and what you are supposed to do with it, these are just possibilities. There are many different possible scenarios regarding how the file is set up and several different ways to accomplish any given task to use the data in the file, but first you must know the specifics of the data, what you want to do with the data, and what tools you have available to accomplish the task.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396