Templates 677
19
101: {
102: cout << “Enter an offset (0-9) “;
103: cout << “and a value. (-1 to stop): “;
104: cin >> offset >> value;
105:
106: if (offset < 0)
107: break;
108:
109: if (offset > 9)
110: {
111: cout << “***Please use values between 0 and 9.***\n”;
112: continue;
113: }
114:
115: theArray[offset] = value;
116: }
117:
118: cout << “\nHere’s the entire array:\n”;
119: cout << theArray << endl;
120: return 0;
121: }
LISTING19.4 continued
If you are using a Microsoft compiler, uncomment line 42. Based on the C++
standards, this line should not be necessary; however, it is needed to com-
pile with the Microsoft C++ compiler.
NOTE
Enter an offset (0-9) and a value. (-1 to stop): 1 10
Enter an offset (0-9) and a value. (-1 to stop): 2 20
Enter an offset (0-9) and a value. (-1 to stop): 3 30
Enter an offset (0-9) and a value. (-1 to stop): 4 40
Enter an offset (0-9) and a value. (-1 to stop): 5 50
Enter an offset (0-9) and a value. (-1 to stop): 6 60
Enter an offset (0-9) and a value. (-1 to stop): 7 70
Enter an offset (0-9) and a value. (-1 to stop): 8 80
Enter an offset (0-9) and a value. (-1 to stop): 9 90
Enter an offset (0-9) and a value. (-1 to stop): 10 10
***Please use values between 0 and 9.***
Enter an offset (0-9) and a value. (-1 to stop): -1 -1
Here’s the entire array:
[0] 0
[1] 10
[2] 20
[3] 30
[4] 40
OUTPUT