//while.cpp #include int main() { cout << "How many items would you like to average? " << endl; int number_of_items; cin >> number_of_items; cout << number_of_items << "\n\n"; //echo input int k=0, sum=0; //initialize counter and sum variables while (k < number_of_items) { int number; //declare local variable, "number" k++; //increment counter cin >> number; //input next number cout << number << endl; //echo input sum += number; //add to accumulating sum } // NOTE:  The variable 'number' is unknown outside its scope, // so, cout << number << endl; would give error message here. int average=0; if (k>0) average=sum/k; cout << "average = " << average << endl; //ALTERNATIVE (to output "real" average) //float average = 0.0f; //if (k>0) // average = static_cast (sum)/k; //NOTE: Remember that "real" constants are by default of type double, //so //float x = 1.2; //instead of //float x = 1.2f; //would generate the following warning: //'initializing' : truncation from 'const double' to 'float' return 0; }