Here's a program that is very similar to yours, but not enough so that you can copy it directly. It should give you some ideas and examples you can use. By understanding the comments and using similar comments in your program I think you can take it from here if you follow my previous posts.
Note: this program has not been compiled yet so there may be some errors. It is meant to be an example, not a solution.
Code:
#include <fstream.h>
//global constants to use throughout program
const int ROW = 2;
const int COL = 3;
int main()
{
int i, j;
//container to hold data read from file
//each int in table initialized to -1111 as default values;
int table[ROW][COL] = {-1111};
//display table with all defalut values
for(i = 0; i < ROW; i++)
{
for(j = 0; j < COL; j++)
{
cout << table[i][j] << ' ';
}
cout << endl;
}
//create a data file with some easy to use numbers
ofstream fout("data.txt")
fout << 50 << ' ' << 90 << ' ' << 70 << endl;
fout << 80 << ' ' << 90 << ' ' << 100;
//declare ifstream to read back data to program
ifstream fin("data.txt");
//assign default values to index variables
i = 0;
j = 0;
//read in first value to fist spot in table, then go to next col
fin >> table[i][j++];
//as long as fin is valid
while(fin)
{
//if at end of first row
if(j == 2)
{
//reset columns to 0;
j = 0;
//go to next row
i++;
}
//read in next value from file
fin >> table[i][j++];
}
//display table of values read in from file
for(i = 0; i < ROW; i++)
{
for(j = 0; j < ROW; j++)
{
cout << table[i][j];
}
cout << endl;
}
//check value in first spot of table, if it's still default value
if(table[0][0] == -1111)
cout << "file was empty" << endl;
else
{
//read table to develop student average first and then
//exam score averages
int sum;
double ave;
//calculate each students average
//use one row at a time
for(i = 0; i < ROW; i++)
{
//set default values for sum and ave for each student
sum = 0;
ave = 0.0;
for(j = 0; j < COL; j++)
{
//add each value in line to sum
sum = sum + table[i][j];
}
//calucluate ave
ave = sum/j;
//display results
cout << "student " << (i + 1) << " has average score of " << ave << endl;
}
//calculatae average score for each exam
//now use one column at a time
for(j = 0; j < COL; j++)
{
sum = 0;
ave = 0.0;
//add each value in column to sum
for(i = 0; i < ROW; i++)
{
sum += table[i][j];
}
//calculate average score on exam
ave = sum/i;
//display result
cout << "ave score on exam " << j +1 << " was " << ave << endl;
}
}//end else
return 0;
}
edit: had rows and columns switched orignially. Now corrected. Sorry.