go to previous page   go to home page   go to next page        

Answer:

Yes, although this method is sometimes awkward.

Sentinel Controlled Input Loops

One of the types of loops is a "sentinel" controlled loop, where a special input value indicates that there is no more data. This idea can be used with input files as well. Say that your program is to add up the integers in a file of data. The integers are all expected to be positive integers, so the sentinel value can be any negative integer. Here is a data file where each group of student grades is followed by -1, the sentinel.

87
98
95
-1          
78
82
91
84
-1

The program should average three integers in this file and four integers in the second (and not include the negative values in eithere average).

QUESTION 14:

  1. What is an advantage of this form of input file?
  2. What is a disadvantage of this form of input file?