// This program illustrates a sentinel controlled while loop. // Write a program that calculates the average of an unknown number of positive integers. // The program is to stop when a negative integer is entered. #include using namespace std; int main() { int value, count, sum; count = 0; cout << "Please enter positive integers, a -1 to stop" << endl; cin >> value; // initialize while (value != -1) // test { sum += value; count++; cin >> value; // modify } cout << " The average is " << (double)sum / count << endl; }