473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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?
May 17 '10 #1
4 2565
Christian Binder
218 Expert 100+
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).Average(); // =9
May 17 '10 #2
Curtis Rutland
3,256 Expert 2GB
@ChBinder
Close, but your example selects 6 and 8, making avg == 7.

You would need to use OrderByDescending.

@s207044707
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.
May 17 '10 #3
tlhintoq
3,525 Expert 2GB
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.
May 17 '10 #4
jkmyoung
2,057 Expert 2GB
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.
May 17 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dcass | last post by:
how do you add three numbers then average the same three numbers, while using the get_data and average functions.
18
by: Rose4msm | last post by:
hello can any one please help me i have a test and i need to study the java scripts, i know that i have to use arrays but im still a bit confuse the question is to ask the user how many data items...
30
by: Amar Kumar Dubedy | last post by:
How to find the greatest of three numbers without using any comparison operator or ternary operator??
2
by: Terry Olsen | last post by:
I have an array filled with counts of numbers. Example: ar(1) contains the number of occurrances of the number 1 ar(2) contains the number of occurrances of the number 2 etc... I need to find...
11
by: zj262144 | last post by:
Hi, I'm a C beginner. I want to write a C. The pseudocodes are like this: User enters some numbers (use -1 to end) The compiler find and delete the maximum and minimum numbers Then average...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.