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

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 will average the first three integers and and then the four integers after the first minus one (but not include the negative values in either 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?

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