Help with simple in/outfile?

I get as far as the output screen with the correct structure but the numbers are nonsense. Help?

My program and .dat are in the same subcategory.
.dat->
1
2
3
4
5
6
7
8
9
10
11
12

Write a C++ program to open the file “infile.dat”, read the 10 integers, and compute their average. Then write the result to the file “outfile.dat” with the message “The average is XXX.X.” where XXX.X is a real number. You can assume that there are 12 integers stored in the file “infile.dat”.

#include<iostream>
using namespace std;
#include<iomanip>
using std::setw;
using std::setprecision;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <cmath>
double average (double a[], int size);
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;
}
Hi. Before we get our hand dirty. There are some things considered good and bad forum behavior. On the bad list is not using tags, like code tag. An other thing while we're at it, not stating what's gnarly and what one has done to try and fix it.

Welcome!!!
Thanks. code tag being..?
Next to the text-area, or under depending on what view you're in, you have buttons. They're grouped under Format, click on a button looking like this <>
Topic archived. No new replies allowed.