Dec 1, 2011 at 1:13pm UTC
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;
}
Dec 1, 2011 at 2:31pm UTC
How would I do that sir? I hate to admit it, but I'm still very horrible at this.
Dec 1, 2011 at 3:18pm UTC
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.