// fileOfInt2.cc P. Conrad 02.14.06  for CISC181
// read an input file of integers and print the sum
// this fixes the bug that was in fileOfInt.cc
//  by using a #define for the filename

#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)
{
  int sum;
  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;
      infile >> x;
    }


  cout << "The sum is " << sum << endl;
  return 0;
}

