How to get 2 maximum numbers out of three numbers?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • s207044707
    New Member
    • May 2010
    • 1

    How to get 2 maximum numbers out of three numbers?

    HI

    I need to create a programm that stores 10 users, and three numbers for each user, and calculate average for each user based on the three numbers entered e.g. if user 1 entered 6, 8 ,10, then average =(8+10)/2=80.0%.Then how to select 8 and 10?
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    Hi,
    I don't know how these values are hold, but if they're in an array or list you could do it using LINQ:

    int[] inputs = new int[] { 6, 8, 10 }; // User-Input

    double avg = inputs.OrderBy( x => x).Take(2).Aver age(); // =9

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Originally posted by ChBinder
      Hi,
      I don't know how these values are hold, but if they're in an array or list you could do it using LINQ:

      int[] inputs = new int[] { 6, 8, 10 }; // User-Input

      double avg = inputs.OrderBy( x => x).Take(2).Aver age(); // =9
      Close, but your example selects 6 and 8, making avg == 7.

      You would need to use OrderByDescendi ng.

      Originally posted by s207044707
      HI I need to create a programm that stores 10 users, and three numbers for each user, and calculate average for each user based on the three numbers entered e.g. if user 1 entered 6, 8 ,10, then average =(8+10)/2=80.0%.Then how to select 8 and 10?
      This seems like a homework problem. The problem with us telling you the solution like this is that it's probably not the way the instructor wanted you to do it. I could give you the way that I would do it, but if that's not the point of the assignment, then your instructor will know that you did not do the work yourself, and you will likely get a bad grade.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Bytes has a policy regarding assisting students with their homework.

        The short version is that the volunteers here can't help you with schoolwork.
        A) We don't know what material you have and have not learned in class.
        B) We don't know the guidelines you must follow.
        C) In the long run giving you the answers actually short changes your education.

        Hint 1: Try hitting Google with terms of your programming language and primary terms of what you want to do. For example "C# custom events" or "VB datagrid Excel". I've found this to be a very effective tool.
        Hint 2: Your text book
        Hint 3: Your instructor
        Hint 4: Posting guidelines regarding homework assignments.

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          This sounds like the classic grading problem, drop the lowest test.

          Try framing your problem in this way: As opposed to taking the top 2, take all 3 then drop the lowest value. Same result.

          Comment

          Working...