No, any special user input could work.
Sometimes a program asks the user if the loop should continue before each iteration. The user enters "yes" or "no" (or maybe "y" or "n").
Now the sentinel is of type String
.
The next example illustrates this:
Say that you are interested in the value of this polynomial for various values of x:
7x3- 3x2 + 4x - 12
The variable x is double precision.
For example, when x == 2.0 the polynomial is equal to:
7*23- 3*22 + 4*2 - 12 = 7*8 - 3*4 + 8 - 12 = 40
The program asks the user to enter various values for x and displays the result for each one.
Would using a special value of x (such as 0.0) work as a sentinel?