Help please!

This is a discussion on Help please! within the C++ Programming forums, part of the General Programming Boards category; I trying to write a program that finds the largest number from a known quantity of integers and also finds ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    2

    Help please!

    I trying to write a program that finds the largest number from a known quantity of integers and also finds the smallest integer from a unknown quantity of integers.

    These options should be acessed through a menu that looks like this:
    A - Find the largest # with a known quantity of numbers
    B - Find the smallest # with an unknown quantity of numbers
    C - Quit
    Please enter your choice ___

    ...and should repeat until the user choses option C

    My problem is figuring out how to use a loop to find the largest and smallest integers in options A and B. I know that I have to cin the input values to a variable to compare it to the largest of the values entered but I having a hard time figuring it out. Any help would be greatly appreciated.

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Why don't you post your try(s)? We aren't here to do your homework for you.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    2
    Well, I don't recall asking anyone to write the code for me. I was simply trying to see if anyone could give me insight on how to use a for loop to output the largest or smallest integer out of a certian quantity of numbers. I don't really have a complete "try" as I've been stuck on how to do this. I understand how to use the loop to find averages and sums, but this particular operation I'm not quite understanding. If this is the wrong place to be asking these questions please let me know or point me in the right direction.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Code:
    declare number = 0;
    for start to end {
        if start {
            number = index_value
        }
    
        if index_value > number { // looking for largest
            number = index_value
        }
    }
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21