Sentinel value in algorithm

  • #1
332
1

Main Question or Discussion Point

Hi

Please have a look on this scanned page:
http://img257.imageshack.us/img257/8175/chap11page191.jpg

I humbly request you to be precise and to the point in your replies. I need you help and need to understand this as soon as possible. Thank a lot.

Suppose there were 100 students and once it has processed the percentage of the last student (100th) it writes output data and then goes back to first step "Read Input Data" as the 'arrow line' suggests. Well, there is any more Input Data so the program will keep on looking for the Input Data. How is it suppose to lead to the step "Is Roll no. = 0000000" - a sentinel value? I don't understand it.

Please help me.
 

Answers and Replies

  • #2
33,514
5,195
Using a sentinel or trailer value, the program doing the processing doesn't need to know how much data there is.

Basically the program reads a student ID. If the ID is 0000000, the program stops. If the ID is not 0000000, it reads in data about that student, does some calculations, and then goes back to read another student ID.
 
  • #3
jtbell
Mentor
15,545
3,467
In order for the algorithm to work properly, the input data file must be constructed so that the last line or data set contains 0000000 in the position that normally contains the roll number. This last line is not intended to be used as "real data." It exists only as a "sentinel" which signals that there is no more "real data."
 
  • #4
332
1
I understand it now. Thank you, both of you, Mark, JT. These are the answers I call concise and to the point. Or, as you say in English, don't give me what I ask for, give me what I need.

Best wishes
Jackson
 

Related Threads on Sentinel value in algorithm

Replies
4
Views
2K
  • Last Post
Replies
9
Views
2K
Replies
25
Views
2K
Replies
3
Views
2K
  • Last Post
Replies
0
Views
561
  • Last Post
Replies
3
Views
11K
Replies
1
Views
2K
Replies
4
Views
2K
  • Last Post
Replies
22
Views
2K
  • Last Post
Replies
2
Views
2K
Top