Results 1 to 12 of 12

Thread: amateur

  1. #1
    monaghan is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default amateur

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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: amateur

    What is meant by your subject line amateur?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: amateur

    That could be an arithmetic expression that returns the value of the sentinel variable minus 1
    A usage:
    y = x - 1
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    monaghan is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: amateur

    Quote Originally Posted by Norm View Post
    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);

    }

    }

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    monaghan is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default 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. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,725
    Blog Entries
    7
    Rep Power
    21

    Default Re: amateur

    You still haven't answered the question from reply #1.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    monaghan is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default 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. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: amateur

    The code in post#4 uses a sentinel to stop getting user input.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    monaghan is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default 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

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: amateur

    Where is the variable: keyboard defined in your program? The compiler can not find a definition for it
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. An amateur Java Tutorials Site
    By elasolova in forum Reviews / Advertising
    Replies: 1
    Last Post: 01-18-2008, 10:23 PM

Posting Permissions

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