Finding averages of columns and rows from 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

#include <iostream> //For basic input and output of data.
#include <iomanip> //For manipulation of data output.
#include <conio.h> //?
#include <fstream> //For file output.
#include <string>
#include <cmath> //For math functions.
using namespace std;

int main ()
{
//Putting the data into an array.

{

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;
}

for (int x = 0; x < 5 && !inFile.eof(); x++)
{
for(int y = 0; y < 2; y++)
{
inFile >> SampleSet[x][y];
cout <<SampleSet[x][y] << " ";
}
cout << endl;
}

inFile.close();
}

//Finding the averages

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;
}
}
Topic archived. No new replies allowed.