#include #include #include using namespace std; // file: stats3.cpp; author: D. Ramm; date: 10/15/9; mod: 2/17/00 // file input; while with EOF to exit // move count to function with reference parameter void Count(int & tally) { tally++; } int main() { int number, count = 0; string filename; ifstream filein; cout << "Enter file name: "; cin >> filename; filein.open(filename.c_str()); while (filein >> number) { Count(count); cout << "Do something with number: " << number << endl; } if (count == 0) cout << "No data found in file " << filename << endl; else cout << count << " numbers were read." << endl; return 0; } /* Sample output: prompt> stats3 Enter file name: data Do something with number: 1 Do something with number: 2 Do something with number: 4 Do something with number: 7 Do something with number: -2 Do something with number: 33 Do something with number: -11 Do something with number: 12 8 numbers were read. */