/* testarr04.cpp CIS 150 06/23/2005 David Klick Demonstration of setting array elements from user input. */ #include using std::cout; using std::cin; // common way to set array size globally const int ARRAY_SIZE = 10; int main(void) { double nums[ARRAY_SIZE]; int numItems = 0; // number of items stored in array int ctr; double sum; // get values for array from user, but don't // allow array to overflow while (numItems < ARRAY_SIZE) { cout << "Enter item #" << (numItems+1) << " (-999 to quit): "; cin >> nums[numItems]; // stop if user enters -999 if (nums[numItems] == -999) break; // keeps track of how many items are in the array numItems++; } // skip this section if nothing was entered if (numItems > 0) { // display all items stored in array cout << "You entered:\n"; for (ctr=0; ctr