/* testalloc2.cpp CIS 150 David Klick 6/28/05 Demonstration of allocating memory for an array. */ #include using std::cout; using std::cin; int main(void) { int size; // holds size of array int i, sum; int *arr; // pointer for array we will create // find out how large the user would like the array to be do { cout << "Enter array size (1-10): "; cin >> size; if (size < 1 || size > 10) { cout << "Error: Invalid size\n"; } } while (size < 1 || size > 10); // create the array arr = new int[size]; // get numbers for array from user for (i=0; i> *(arr+i); } // add up all the elements of the array sum = 0; for (i=0; i