Please help with 2d-array

Hello, I am working on a array with 7 columns and 8 rows and I am attempting to calculate the average of each row individually and also each column individually. So far I am able to get the titles to appear but each calculation is way above what it should be. Would anyone happen to have any advice or anything to fix my issue? Thanks ahead of time!
#include<iostream> //required for cin, cout
#include<cstdlib>
#include<fstream> //required for ifstream, ofstream
#include<string> //required for string characters
#include<cmath> //reqired for math operators

using namespace std;
int main()
{

const int NROWS{ 7 };
const int NCOLS{ 8 };
double plant[NROWS][NCOLS], sum, avg;
string filename;
ifstream data1;

cout << "Enter input name of file.\n";
cin >> filename;
data1.open(filename);
if (data1.fail())
{
cerr << "Error opening data file\n";
exit(1);
}

for (int i = 0; i < 7; i++)
{

sum = 0;
for (int j = 0; j < 1; j++)
{
sum =sum + plant[i][j];
}
avg = sum / 7;

cout << "week" << 1 << ":Average-" << avg<<"MW"<< endl;

}

for (int i = 0; i < 7; i++)

{
sum = 0;
for (int j = 0; j < 8; j++)
{
sum = sum + plant[j][i];
}
avg = sum /8;

cout << "day" << i+1 << ":Average =" << avg <<"MW"<< endl;

}
data1.close();
system("pause");
return 0;
}

Shouldn't you read the data into your array before you do any calculations ?
Yeah, I have the data saved on a file called plant.dat then when I run the program I am able to enter the file name in and the program collects the data from the file. It may not be reading it correctly though.
mdburns wrote:
It may not be reading it correctly though.

Please explain on which line of the program that you have posted ... where it is reading ANYTHING from file.
I thought the lines with the " for(int j=0;j<8;j++) and for (int i=0;i<7;i++)" were taking data from the file. Sorry I am still new to the c++ language.
I thought the lines with the " for(int j=0;j<8;j++) and for (int i=0;i<7;i++)" were taking data from the file.

No. Nothing about those lines has anything to do with files. Those lines each define a loop.

See http://www.cplusplus.com/doc/tutorial/control/ for a tutorial about loops, if you don't know what they are.

For a tutorial on reading data from files, see:

http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.