
// reads ints from a file - terminates on end of file
// adds the ints and displays the sum
// promtps for filename
// WRONG!
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
   ifstream infile;
   string filename;
   cout << "Enter file name " << endl;
   cin >> filename;
   infile.open(filename.c_str());
   if (infile.fail())
   {
      cerr << "File not found " << endl;
      return EXIT_FAILURE;
   }
   int x;
   int sum = 0;
   while (!infile.eof())
   { 
      infile >> x;
      sum = sum + x;
   }
   cout << "sum is " << sum << endl;
   system("pause");
   return EXIT_SUCCESS;
}
    

