2-dimensional arrays

I'm trying to take a list of student id numbers along with a list of grades for each student for 5 quizes, store them into a 2-dimensional array, then output the minimum, maximum, and average for each column. I need help on how to do the minimum and maximum for each individual column ( excluding column 1, which is the student ID#s). PS, this is due tonight. He gave us the project after class today, but I had to work til 10, so I've only had about 45 mins to work on it so far and I really need help. The text file looks like this:

666 052 007 100 078 034
667 090 036 090 077 030
668 100 045 020 090 070
669 011 017 081 032 077
670 020 012 045 078 034
671 034 080 055 078 045
672 060 100 056 078 078
673 070 010 066 078 056
674 034 009 077 078 020
675 045 040 088 078 055
676 055 050 099 078 080
677 022 070 100 078 077
678 089 050 091 078 060
679 011 011 000 078 010
680 000 098 089 078 020
681 078 083 087 091 086
682 067 077 084 082 079
683 077 089 093 087 071
684 078 089 093 091 086
685 067 077 084 082 071
686 074 083 088 086 078
687 090 080 081 090 077
688 060 036 066 090 100
689 070 080 077 077 077
690 055 070 088 032 072
691 089 098 099 090 086


and my source file, thus far is:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
ifstream infile;//input file name
int quizarr[ 26 ][ 6 ];//declares two dimensional array of 26 rows, 6 columns
int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;
int max1 = 0, max2 = 0, max3 = 0, max4 = 0, max5 = 0;
int min1 = 0, min2 = 0, min3 = 0, min4 = 0, min5 = 0;
int r = 0, c = 0, next;// rows and columns
cout << "Program is now opening 'QuizGrades.txt'" << endl << endl;
infile.open( "QuizGrades.txt" );//QuizGrades.txt
if(!infile)
{
cerr<<"ERROR 001 OCCURRED WHEN ATTEMPTING TO OPEN 'QuizGrades.txt'\n\n"<<endl;//shows error if QuizGrades.txt does not open
exit(001);
}//end if
cout << "Program is now storing the students ID numbers and quiz grades into an array.\n\n";
cout << setw (10) << "ID #";
cout << setw (10) << "Quiz 1";
cout << setw (10) << "Quiz 2";
cout << setw (10) << "Quiz 3";
cout << setw (10) << "Quiz 4";
cout << setw (10) << "Quiz 5";
cout << endl << endl;
for ( r = 0; r < 26; r++ )
{
for ( c = 0; c < 6; c++ )
{
infile >> quizarr[r][c];
cout << setw (10);
cout << quizarr[r][c];
}//end for
cout<< endl;
}//end for
for ( r = 0; r < 26; r++ )
{
sum1 += quizarr[r][1];
sum2 += quizarr[r][2];
sum3 += quizarr[r][3];
sum4 += quizarr[r][4];
sum5 += quizarr[r][5];
}//end for
cout << endl << "______________________________________________________________________" << endl << endl;
cout << setw (10) << "Average:";
cout << setw (10) << setprecision(4) << sum1/26.0;
cout << setw (10) << setprecision(4) << sum2/26.0;
cout << setw (10) << setprecision(4) << sum3/26.0;
cout << setw (10) << setprecision(4) << sum4/26.0;
cout << setw (10) << setprecision(4) << sum5/26.0 << endl << endl;
cout << setw (10) << "Minimum:";
cout << setw (10) << min1;
cout << setw (10) << min2;
cout << setw (10) << min3;
cout << setw (10) << min4;
cout << setw (10) << min5 << endl << endl;
cout << setw (10) << "Maximum:";
cout << setw (10) << max1;
cout << setw (10) << max2;
cout << setw (10) << max3;
cout << setw (10) << max4;
cout << setw (10) << max5 << endl << endl;
infile.close( );//closes input file
system("PAUSE");
}//end main
Well, I figured it out. Here's the completed source code thanks to no one, but myself... even though it was due an hour & a half ago.

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
ifstream infile;//input file name
int min[ 5], max[ 5 ];//arrays for min and max value of each column
int quizarr[ 26 ][ 6 ];//declares two dimensional array of 26 rows, 6 columns
int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;//totals for each column
int r = 0, c = 0;// rows and columns
cout << "Program is now opening 'QuizGrades.txt'" << endl << endl;
infile.open( "QuizGrades.txt" );//opens QuizGrades.txt
if( !infile )
{
cerr << "ERROR 001 OCCURRED WHEN ATTEMPTING TO OPEN 'QuizGrades.txt'\n\n" << endl;//shows error if QuizGrades.txt does not open
exit( 001 );//exits the program if file is not opened
}//end if
cout << "Program is now storing the students ID numbers and quiz grades into an array \nand calculating the average, maximum, and minimum for each quiz.\n\n";
cout << "Press any key to get to the quiz grades.\n\n";
system ( "PAUSE" );//pauses the output screen
system ( "CLS" );//clears the output screen
cout << setw ( 12 ) << "ID #" << setw ( 12 ) << "Quiz 1" << setw ( 12 ) << "Quiz 2" << setw ( 12 ) << "Quiz 3" << setw ( 12 ) << "Quiz 4" << setw ( 12 ) << "Quiz 5" << endl << endl;
for ( r = 0; r < 26; r++ )//puts each ID# and quiz grade into their appropriate positions in the 2-dimensional array
{
for ( c = 0; c < 6; c++ )
{
infile >> quizarr[ r ][ c ];
cout << setw ( 12 );
cout << quizarr[ r ][ c ];
}//end for
cout << endl;
}//end for
cout << endl;
system ("PAUSE");
system("CLS");
cout << setw ( 12 ) << "ID #" << setw ( 12 ) << "Quiz 1" << setw ( 12 ) << "Quiz 2" << setw ( 12 ) << "Quiz 3" << setw ( 12 ) << "Quiz 4" << setw ( 12 ) << "Quiz 5" << endl << endl;
for ( r = 0; r < 26; r++ )//puts each ID# and quiz grade into their appropriate positions in the 2-dimensional array
{
for ( c = 0; c < 6; c++ )
{
cout << setw ( 12 );
cout << quizarr[ r ][ c ];
}//end for
cout << endl;
}//end for
for ( r = 0; r < 26; r++ )//determines the sum for each column ( excluding column 0 )
{
sum1 += quizarr[ r ][ 1 ];//sum for column 1
sum2 += quizarr[ r ][ 2 ];//sum for column 2
sum3 += quizarr[ r ][ 3 ];//sum for column 3
sum4 += quizarr[ r ][ 4 ];//sum for column 4
sum5 += quizarr[ r ][ 5 ];//sum for column 5
}//end for
for ( c = 1; c < 6 ; c++ )
{
min[ c ] = quizarr[ 0 ][ c ]; //assumes first element in cth Column is min
max[ c ] = quizarr[ 0 ][ c ]; //assumes first element in cth Column is max
for ( r = 1; r < 26; r++ )//finds the min and max value for each column
{
if ( max[ c ] < quizarr[ r ][ c ])
{
max[ c ] = quizarr[ r ][ c ];
}//end if
if ( quizarr[ r ][ c ] < min[ c ] )
{
min[ c ] = quizarr[ r ][ c ];
}//end if
}//end for
}//end for
cout << endl << "________________________________________________________________________________" << endl << endl;
cout << setw ( 12 ) << "Average:" << setw ( 12 ) << setprecision( 4 ) << sum1 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum2 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum3 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum4 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum5 / 26.0 << endl << endl;
cout << setw ( 12 ) << "Minimum:" << setw ( 12 ) << min[ 1 ] << setw ( 12 ) << min[ 2 ] << setw ( 12 ) << min[ 3 ] << setw ( 12 ) << min[ 4 ] << setw ( 12 ) << min[ 5 ] << endl << endl;
cout << setw ( 12 ) << "Maximum:" << setw ( 12 ) << max[ 1 ] << setw ( 12 ) << max[ 2 ] << setw ( 12 ) << max[ 3 ] << setw ( 12 ) << max[ 4 ] << setw ( 12 ) << max[ 5 ] << endl << endl;
system( "PAUSE" );//pauses the output screen
system( "CLS" );//clears the output screen
cout << "The program is now closing the input file 'QuizGrades.txt'\n\n";
infile.close( );//closes input file
cout << "The program has completed all necessary tasks.\n\n";
system( "PAUSE" );
}//end main
So you posted it a little bit before your due date, and didn't even bother formating your code with [code][/code] tags. And bother to point out "thanks to no one but yourself" ...
So, if you read the description, I said The teacher gave us the assignment in class at 3:00, I had to work from 4:00-10:00, I got home at 10:45, and it was due by midnight, which means I had a grand total of 1 hour and 15 minutes to complete it and email it to the professor. Thanks for posting a sarcastic comment when you obviously didn't even thoroughly read the description.
Thanks for posting a sarcastic comment when you obviously didn't even thoroughly read the description.


Maybe you should read the forum rules (ie. how to use code tags). It is not anyone's problem how your work schedule conflicts with your assignments. Try being a little less rude and maybe you will get better responses.
Topic archived. No new replies allowed.