1. Member
Join Date
Apr 2012
Posts
5
Rep Power
0

## amateur

what is meant by sentinel -1 and how would i use it in a program?

2. ## Re: amateur

What is meant by your subject line amateur?

db

3. ## Re: amateur

That could be an arithmetic expression that returns the value of the sentinel variable minus 1
A usage:
y = x - 1

4. Member
Join Date
Apr 2012
Posts
5
Rep Power
0

## Re: amateur

Originally Posted by Norm
That could be an arithmetic expression that returns the value of the sentinel variable minus 1
A usage:
y = x - 1
I am only new at programming and am been asked to write a program that allows a user to enter a series of numbers and when the sentinel -1 is entered the largest number is printed out on the screen, but i am stuck with what the sentinel means and how i would use same; this is my program so far but i cant find my way out any help greatly appreciated

public class sentinel {

public static void main (String[]args) {
int x;
Screen.message("PE enter series of numbers");
do
while(x!=-1);

}

}

5. ## Re: amateur

What does google give for the meaning of sentinel?
Can you post the definition you get and then ask questions if you don't understand it.

Does your code work as you want it to? If not, please explain what happens that is not what you want.

6. Member
Join Date
Apr 2012
Posts
5
Rep Power
0

## Re: amateur

Sentenal=In programming, a special value that is used to terminate a loop. The sentinel value typically is chosen so as to not be a legitimate data value that the loop will encounter and attempt to perform with. For example, in a loop algorithm that computes non-negative integers, the value "-1" can be set as the sentinel value as the computation will never encounter that value as a legitimate processing output.

In My program i wish to enter 5 numbers and have the screen only output the highest number!

7. ## Re: amateur

kind regards,

Jos

8. ## Re: amateur

Getting 5 numbers is different than getting numbers UNTIL the user enters a number with a value of -1.
You would use a for loop that loops 5 times for that.
To find the largets: In the loop you would need to use a if statement to compare what the user entered against the value of the current largest number. If new is larger, then save the new one as the current largest.

9. Member
Join Date
Apr 2012
Posts
5
Rep Power
0

## Re: amateur

thanks for your help, am going to try that- the original question was - (a)write a program that allows a user to enter a series of numbers and when the sentinel -1 is entered the largest number is printed out on the screen.!...still not exactly sure how to implement this in the program!

10. ## Re: amateur

The code in post#4 uses a sentinel to stop getting user input.

11. Member
Join Date
Apr 2012
Posts
5
Rep Power
0

## Re: amateur

dont understand your answer, but maybe you can help in explaining why the program is issuing the following message

12. ## Re: amateur

Where is the variable: keyboard defined in your program? The compiler can not find a definition for it

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•