// findAvg.cc  Bill    02.14.06  for CISC181
//   assisted by Nikhil, Tom and Spencer

// find the average of an input file

#include <iostream> // we are doing normal keyboard i/o 
#include <fstream>
using namespace std; // we'll talk about this later

#define INFILE_NAME "nums.dat"

int main(void)
{
  double avg=0, sum=0;
  int i=0;
  int x;

  ifstream infile(INFILE_NAME,ios::in);

  if (!infile)
    {
      cerr << "Sorry, I could not open "  INFILE_NAME << endl;
      return 1;
    }

  infile >> x;
  while (!infile.eof())
    {
      
      sum = sum + x;
      i++;

      infile >> x;
    }
  avg=sum/i;


  cout << "The average is " << avg << endl;
  return 0;
}

