Finding Averages of columns and rows in an array?

Hi, very new to C++, am trying to find averages for columns and rows in an array which has been input from a txt file. Any help is appreciated.Thanks

The text file:
x y
1 3
2 4
3 5
4 8
5 11


{

int SampleSet[5][2]; //An array with 5 rows and 2 columns
ifstream inFile ("SampleSet.txt");
int x = 0;
int y = 0;
if(!inFile) //Always test the file open.
{
cout << "Error opening output file" <<endl;
system ("pause");
return -1;
}

inFile >> SampleSet[x][y]
while(!inFile.eof())
{
for (int x = 0; x < 5; x++)
{
for(int y = 0; y < 2; y++)
{
SampleSet[x][y] =?
}
}
}
inFile.close();

inFile(5, SampleSet.txt)
cout << "Reading SamplesSet.txt...\n";
cout << "Number of elements =" << x << "\n";
cout << "Simple Linear Regression Model : y = 2* x +0.2\n";

//Calculate the simple linear regression model
{
//This Function calculates the average of each col, and row.
void calcAverage(int x, int y, float SampleSet[][5])
{



SampleSets[x-1][y-1] = 0;

for (int i = 0; i <x-1; i++)
{
float sum = 0;
for (int j = 0; j < y-1; j++)
{
sum += SampleSet[i][j];
}
numbers[i][x-1] = sum/(y-1);
}


for (int j = 0; y < y-1; j++)
{
float sum = 0;
for (int i = 0; i < x-1; i++)
{
sum += SampleSet[i][j];
}
SampleSet[x-1][j] = sum/(x-1);
}
}


float average(float a[],int n);

{

float average, sum = 0;
for (int i = 0; i < n; i++)
sum += a[i];
average = sum / n;
return 0;

}

void output(int x, int y, float SampleSet [][5])
{
cout << setprecision(2) << fixed << showpoint;
for(int i = 0;i < x;i++)
{
for(int j = 0;j < y;j++)
cout << setw(7) << SampleSet[i][j];
cout << endl;
}
}


i am sorry but your code is unreadable ...try posting again
Topic archived. No new replies allowed.