// Ch. 5 Demo Program #4
// Purpose - to demonstrate reading data from one file and writing data to another file.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
   int i = 0;
   int nextNum = 0;
   int sum = 0;
   double average = 0.0;

   ifstream infile("data.txt");
   ofstream outfile("results.txt");

   for (i = 0; i < 5; i++)
   {
      infile >> nextNum;
      sum = sum + nextNum;
   }

   average = sum / 5.0;

   outfile << average << endl;

   cout << "This program computed the average of the five numbers in the file opened for input" << endl;
   cout << "and it stored the average of those numbers in the file opened for output" << endl;

   outfile.close();
   infile.close();

   return 0;
}// end of main