// Add the numbers in a file and find their average. // Michael Rothstein // 3/3/14 #include #include #include using std::cin; using std::cout; using std::endl;using std::ifstream; using std::cerr; int main(int argc,char *argv[]){ ifstream data(argv[1]); if (data.fail()){ cerr << "Could not open data file. sorry! \n"; exit(1); } int sum=0,count=0; int dd; data >> dd; while (!data.eof()){ sum+=dd; count++; data >> dd; } cout << "Total is " << sum << " average is " << (double(sum))/count << endl; data.close(); }