Thread: Help Please! New to C

  1. #1
    Unregistered
    Guest

    Help Please! New to C

    I'm sure this is very simply but please explain:
    How can I find the greatest number in a list the user has entered?

    I just don't get how you could compare numbers listed under the same variable.

    Thanks for your time!

  2. #2
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    Posts
    189
    If you want to do it without arrays, you need two variables (it can't be done with just one). Just initialize both (I'll call them inp and max) to the lowest value possible and then follow these two steps:

    - get a number (from user) and put in inp
    - copy inp into max if inp exceeds max


    Put these in a loop; when the loop ends (user hits X or something) you can read the largest value in the list out of max.

    This procedure can easily generalized to find the largest value in an array, which is slightly more useful than getting the largest value inputted from the user.

  3. #3
    Unregistered
    Guest
    Thanks for your help man! I got it to work w/o using an array, Im new to this and just made it more complicated than it was. Appreciate the help...

    razkaz

Popular pages Recent additions subscribe to a feed