Thread: how to sort out and drop the lowest int?

  1. #1
    Registered User
    Join Date
    Jan 2013

    how to sort out and drop the lowest int?

    hey guys, IM SO CLOSE to finishing this program, however I need help on how to sort out and drop the lowest int, between 8 ints. Is there any way I can do this?

    I have these ints:
    grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8

    My program already assigns them values. How can I find the lowest value and drop it?

    I literally do not know where to start, and this is the last thing I need *.*

    Thanks guys!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Perhaps if you had
    int grades[8];

    instead of 8 separately named variables, you could sort the array, and the lowest would be at one end.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    If I gave you 8 apples, could you find the smallest one? How did you do that -- in DETAIL?

    Same logic.

    You might use an int variable min, and initialize it to the size of grade1. Then compare it to the other grade variables. If they're lower, then they become the min value. It's a bit awkward because you don't have an array with an index, but the value can be used.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    I have yet to see the day where someone unnecessarily declares every variable in their program as an array, even though the item count is 1 in most cases.
    Sadly, even that would probably still be better than not using an array where one should be used.

    Some people are just pretty adept at finding the worst possible way of doing things. If there isn't an alarm bell going off in your head saying "there must be a better way", then you are not meant to be a programmer!

    You can do this with or without sorting, obviously without is best if you want to preserve the ordering. Do you?
    But once you find the lowest value, what then? Do you want to shuffle the items over by one and skip that value?
    What if there are two items that are equally lowest? Remove just the first one, or all of them?
    Show some code eh!
    Last edited by iMalc; 02-27-2013 at 12:12 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lowest score drop assignment
    By inobProgram in forum C++ Programming
    Replies: 7
    Last Post: 07-04-2012, 04:52 PM
  2. Drop lowest score?
    By unknownnoob in forum C++ Programming
    Replies: 4
    Last Post: 09-23-2010, 02:27 PM
  3. Lowest Score Drop - C++
    By getName(C-Dub) in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2008, 07:02 PM
  4. Lowest Score Drop
    By naya22 in forum C++ Programming
    Replies: 16
    Last Post: 04-29-2007, 12:48 AM
  5. Drop Lowest Grade then Average
    By cmut in forum C Programming
    Replies: 4
    Last Post: 09-27-2002, 10:19 PM