// // Program to compute average of a sequence of grades // (Version 2) // // Input: sequence of non-negative integers (grades), // terminated by a end of file (control-D). // Output: average of grades. // #include #include // has EXIT_SUCCESS // Post: prompt for next number has been printed. void promptForNext(void) { cout << "Enter next grade, or control-D to quit:\n"; } // ---- main program ---- int main(void) { int count = 0; // how many grades read int total = 0; // running total of grades read int temp; // grade read promptForNext(); while (cin >> temp) // read input and test for end of // file, all in one fell swoop { ++count; total += temp; promptForNext(); } if (count > 0) cout << "Average = " << double(total) / double(count) << endl; else cout << "No numbers entered!\n"; return 0; }