Thread: Unlimited Inputs and Determines which is greatest and lowest

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    32

    Unlimited Inputs and Determines which is greatest and lowest

    Enter how many numbers: 10 (may vary)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    The highest number is 10.
    The lowest number is 1.

    can someone help me with these?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    i have tried to input 10 numbers for example but i couldn't get it determine which is the highest value i've entered and the lowest value....

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, the way it works here is that you TRY something, then ask for help showing what you have done in the source code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    but i couldn't get it determine which is the highest value i've entered and the lowest value.
    Suppose I, being as generous as I am , give you a bag of coins and ask you to find the largest (or smallest) denomination (value) among the coins. How would you do it?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    waaaaaaaaa
    should i manually count it???
    huhuhu

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Create a couple variables to store the highest and lowest values. Initialize the "high" variable to an extremely small value and update it if necessary as you enter in each new value... if the new value entered is more than what is already stored, then change the "high" variable to match the current new value. Do something similar for the "low" variable, initialize it to something really high and then keep testing/comparing it against the new values being entered and update if needed. It's really simple.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    should i manually count it???
    That is not the point. I am trying to get you to come up with an algorithm.

    hk_mp5kpdw has provided you with a possible algorithm, though personally I do not find it intuitive. (When we compare stuff, we typically do not start by comparing the first item with some imaginary extreme value. Rather, we start by comparing the first item with the second item.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    use for loop man

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    is looping involve in this?

    i know how to display the highest and the lowest but in a limited manner

    for example 10 items,

    will i could get it since i could manually compare the 1st number up to the last

    but with 100 items hehehehe i could still manually do that but im looking for a better program

    which could easily compare the highest and the lowest

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah, so that is what you mean by "manual": hardcoding the comparisons.

    Yes, you should use a loop.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    can a loop determine the highest and the lowest value i've input?

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by omarbags View Post
    is looping involve in this?
    Whenever you need to do something repetitively some number of times, looping is always involved.

    Quote Originally Posted by omarbags View Post
    i know how to display the highest and the lowest but in a limited manner

    for example 10 items,

    will i could get it since i could manually compare the 1st number up to the last

    but with 100 items hehehehe i could still manually do that but im looking for a better program

    which could easily compare the highest and the lowest
    The main idea here is to deal with largest-so-far and the current number. Is the current number we're looking at right now the largest number? If so, make a note. If not, we don't care.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    can a loop determine the highest and the lowest value i've input?
    Yes. As I noted, you already have an algorithm outlined to you that uses a loop to do what you want to do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    in which case should i look and focus to be able to run the program correctly?
    c'mon guys a little bit of help here....
    i know you are all genius!
    just a little clue further hehehe!

Popular pages Recent additions subscribe to a feed