// findAvg_quesitonable.cc  P.Conrad    02.14.06  for CISC181
// Some questionable code.... does this work, yes or no?
// if not, why not...

// 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;
    }

  // does this work?

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

    }
  avg=sum/i;

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

