// con1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; int main() { // Version 1: ask the user to enter -1 to end the list int sum = 0, count = 0, inputNum = 100; // 100 just to make sure you enter the loop double average; while (inputNum >= 0) { cout << "Enter the next number (-1 to end): "; cin >> inputNum; if (inputNum >= 0) { sum += inputNum; count++; } } // the following two lines compensate for the -1 entered // which should have //sum++; //count--; // clean up: make sure -1 doesn't affect count or sum average = (double)sum / count; cout << "The average of the " << count << " numbers that you entered is:" << average << endl; return 0; }