amateur

• 04-13-2012, 10:43 AM
monaghan
amateur
what is meant by sentinel -1 and how would i use it in a program?
:(whew):
• 04-13-2012, 12:08 PM
DarrylBurke
Re: amateur
What is meant by your subject line amateur?

db
• 04-13-2012, 01:05 PM
Norm
Re: amateur
That could be an arithmetic expression that returns the value of the sentinel variable minus 1
A usage:
y = x - 1
• 04-13-2012, 01:20 PM
monaghan
Re: amateur
Quote:

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
x=keyboard.readInt();//error: cannot find symbol
while(x!=-1);

}

}
• 04-13-2012, 01:27 PM
Norm
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.
• 04-13-2012, 02:04 PM
monaghan
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!
• 04-13-2012, 02:10 PM
JosAH
Re: amateur
You still haven't answered the question from reply #1.

kind regards,

Jos
• 04-13-2012, 02:12 PM
Norm
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.
• 04-13-2012, 02:21 PM
monaghan
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!
• 04-13-2012, 02:25 PM
Norm
Re: amateur
The code in post#4 uses a sentinel to stop getting user input.
• 04-13-2012, 02:33 PM
monaghan
Re: amateur
dont understand your answer, but maybe you can help in explaining why the program is issuing the following message
x=keyboard.readInt();//error: cannot find symbol
• 04-13-2012, 02:39 PM
Norm
Re: amateur
Where is the variable: keyboard defined in your program? The compiler can not find a definition for it