// // Program to compute average of a sequence of grades // (Version 1) // // Input: sequence of non-negative integers (grades), // terminated by a negative integer. // 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 a negative number 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(); cin >> temp; while (temp >= 0) { ++count; total += temp; promptForNext(); cin >> temp; } if (count > 0) cout << "Average = " << double(total) / double(count) << endl; else cout << "No numbers entered!\n"; return 0; }