#include <iostream>
#include <fstream> #include <iomanip>
using namespace std;
int main()
{
int count;
float x, sum, average;
ifstream data_in;
sum = 0;
count = 0;
data_in.open ("floats.dat", ios::in);
if (data_in) {
cout << "The numbers in the data file are: \n";
do
{
data_in >> x;
cout << "The number coming in is: "<< x << endl;
sum = sum + x; count++;
} while (x!=0);
average = sum / (count-1);
cout.setf(ios::fixed);
cout << "The sum of the numbers is: " << sum << endl;
cout << "The average of the numbers is (does not include the 0)"
<< setprecision(2) <<average << endl;
}
else
{
cout << "An error occured while opening the file.\n";
}
data_in.close();
return 0;
}