//****************************************************************** // Trouble program // This is an example of poor program design, which // causes an error when the program is executed //****************************************************************** #include using namespace std; void CountInts(); int count; // Supposed to count input lines, but does it? int intVal; // Holds one input integer int main() { count = 0; cin >> intVal; while (cin) { count++; CountInts(); cin >> intVal; } cout << count << " lines of input processed." << endl; return 0; } //****************************************************************** void CountInts() // Counts the number of integers on one input line (where 99999 // is a sentinel on each line) and prints the count // Note: main() has already read the first integer on a line { count = 0; // Side effect while (intVal != 99999) { count++; // Side effect cin >> intVal; } cout << count << " integers on this line." << endl; }