Sams Teach Yourself C++ in 21 Days

(singke) #1
Managing Arrays and Strings 431

13


34: };
35: cout << endl << “Next number = “;
36: cin >> InputNumber;
37: }
38:
39: for (int Index = 0; Index < ElementsUsedSoFar; Index++)
40: {
41: cout << pArrayOfNumbers[Index] << endl;
42: }
43: return 0;
44: }

Next number = 10

Next number = 20

Next number = 30

Next number = 40

Next number = 50

Next number = 60

Next number = 70

Next number = 0
10
20
30
40
50
60
70
In this example, numbers are entered one after the other and stored in an array.
When a number less or equal to 0 is entered, the array of numbers that has been
gathered is printed.
Looking closer, you can see on lines 6–9 that a number of variables are declared. More
specifically, the initial size of the array is set at 5 on line 6 and then the array is allocated
on line 7 and its address is assigned to pArrayOfNumbers.
Lines 12–13 get the first number from the user and place it into the variable,
InputNumber. On line 15, if the number entered is greater than zero, processing occurs.
If not, the program jumps to line 38.

OUTPUT


LISTING13.9 continued


ANALYSIS
Free download pdf