Need to find the array's average

This is what I've written thus far. I know I'm close, but I can't figure what an arithmetic or enum type is for the power function and how to identify the array and fout the average. Can anyone help?

#include<iostream>
#include<random>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#include<Windows.h>
#include<fstream>
#include<string>

using namespace std;


const int ROWS=10;
const int COLS=7;
double average,sum;
int i,j;


double rand_float(double a,double b)

{
return(double)rand()/RAND_MAX*(b-a)+a; //module for 500-1000 data
}



int main()

{

string filename;
ofstream fout;//this is the power output to be fed into modules

cout<<"Enter filename please"<<endl;
cin>>filename;
fout.open(filename.c_str());

double power[ROWS][COLS];

cout<<setprecision(2);

cout<<setw(7)<<" ";

// print the heading for Days
for(int k=1; k<=COLS; k++)
{
cout<<setw(7)<<"Day"<<setw(3)<<k;
}

cout<<endl<<endl;



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

{

cout<<"Week"<<setw(3)<<i+1; // print the heading for Weeks

for(int j=0; j<COLS; j++)

{
power[i][j]=rand_float(500,1000);// assign random double numbers to the 2D array
cout<<setw(10)<<fixed<<power[i][j];
fout<<average;
}

cout<<endl;

}

for(int i=0; i<ROWS; ++i);
{
for(int j=0; j<COLS; ++j);

{
sum+=array[i][j];

}
}
average=power/(ROWS*COLS);


system("pause");
return 0;


}
Very close, indeed. Your mistake is here:
1
2
3
sum+=array[i][j]; // Should be power[i][j]
...
average=power/(ROWS*COLS); // Should be sum/(ROWS*COLS) 


Other than that, it should be fine, except that you're not outputting your average result.
How would I do that sir? I hate to admit it, but I'm still very horrible at this.
By using "cout" like you have before.

Also, another little note: you never initialized "sum". There is no guarantee it starts at 0. Add "sum = 0;" before you use it.
Topic archived. No new replies allowed.