infile/outfile.dat

Repost without tags
Any help much appreciated!

int main ()
{
const int arraySize=12;
double a[arraySize],m;
ifstream fin;
ofstream fout;
fin.open("infile.dat");
fout.open("outfile.dat");
cout<<"Please enter "<<arraySize<<" integers:\n";
for(int i=0; i<arraySize; i++)
fin>>a[i];
double hold;
for(int i=0; i<arraySize; i++)
for(int j=0; j<arraySize-1; j++)
if(a[j]<a[j+1])
{
hold=a[j];
a[j]=a[j+1];
a[j+1]=hold;
}
cout <<"The numbers in decreasing order are:\n\n";
for (int i=0; i<arraySize; i++)
cout <<setw(5)<<fixed<<setprecision(1)<<a[i]<<endl;
fout <<"The numbers in decreasing order are:\n\n";
for (int i=0; i<arraySize; i++)
fout <<setw(5)<<fixed<<setprecision(1)<<a[i]<<endl;;
cout <<"The sorted data are written to the file: outfile.dat\n";
m = average (a, arraySize);
cout <<"\n The mean is " <<fixed <<setprecision(2)<<m<<endl;
fout <<"\n The mean is " <<fixed <<setprecision(2)<<m<<endl;
fin.close();
fout.close();
return 0;
}
double
average(double a[], int size)
{
double avg=0.0;
for(int i=0; i<size; i++)
avg=avg+a[i];
return avg/size;
}
What's the question????? Please use code paranthesis so that people could read your code.
Topic archived. No new replies allowed.