// readNums.cc pconrad CISC181 02/10/06
// read numbers from a file and find the sum

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

int main(void)
{
  // next line is "special"; we'll discuss on Monday @@@
  // it is called a "Constructor"
  // we won't see these in their full glory until Chapter 6
  
  ifstream infile ("nums.dat", ios::in);

  if (!infile)
    {
      cerr << "Could not open nums.dat, sorry!" << endl;
      exit (1);
    }
  
  // now read all nums from file
  // and find the sum

  int x;
  int sum=0;

  infile >> x;
  while (!infile.eof()) // while not end of file
    {
      sum += x;
      infile >> x;
    }
  
  cout << "the sum is " << sum << endl;
  return 0;


}

