/* Filename: array2.cpp Author: Br. David Carlson Date: January 6, 2000 Modified: June 26, 2000; August 20, 2001 This program prompts the user to enter integers (by first asking the user for the number of integers to be entered). There is no limit on this number of integers. The program computes and prints the average of the integers. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include using namespace std; int main(void) { int Item, NumItems, k; float Sum, Avg; cout << "How many items would you like to enter? "; cin >> NumItems; Sum = 0.0; for (k = 0; k < NumItems; k++) { cout << "Enter an integer: "; cin >> Item; Sum = Sum + Item; } if (NumItems > 0) Avg = Sum / NumItems; else Avg = 0.0; cout << endl << "The average is: " << Avg << endl << endl; return 0; }