#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include<iomanip>
usingnamespace std;
double mean_array(int[], int);
int main()
{
//Now begin reading values from the file.
ifstream inFile;
string filename;
cout << "Which file would you like to open? Include the file's name and extension: "
<< endl;
cin >> filename;
inFile.open(filename.c_str()); //attempt to open file for input
if(!inFile.fail()) //if it doesn't fail, the file exists
{
cout << "A file by the name " << filename << " exists."
<< endl;
}
int value;
int array[5][2];
int k=0;
int i=0;
int SIZE=5;
while(inFile.good()) //continue until the end of the file
{
inFile >> value;
for( i=0; i<5; i++)
{
cout<<endl;
for( k=0; k<2; k++)
{
array[i][k]=value;
cout<<setw(4)<<array[i][k];
inFile >> value;
}
}
cout<<endl;
cout<<"the mean for snowfall is "<< mean_array(array[0][0], SIZE);
}
inFile.close(); //closes the file
return 0;
}
double mean_array(int A[], int SIZE)
{
int total=0;
double mean;
for (int i = 1; i < 13; i++)
{
//cout<<i<<endl;
total = total + A[i];
}
mean= (double) total / (double) SIZE;
return mean;
}