473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Finding the Median of 5 numbers

1 New Member
I have to:
"Use functional decomposition to write a C++ program that determines the median of five input numbers. The median is the middle number when the five are arranged in order. However, the user can input the values in any order, so your program must determine which value is between the other two. For example, if the user enters:

41.52 27.18 96.03 12.5 13.8

then the program would output:

The median of 41.52, 27.18, 96.03, 12.5, and 13.8 is 41.52."

Any Ideas where to start? I am so confused, on how to get a program to find the median.
Mar 17 '07 #1
3 6997
Bl00dFox
12 New Member
I too, am interested in finding the answer... any ideas?
Mar 18 '07 #2
scruggsy
147 New Member
One way to go about it would be to first sort the numbers from lowest to highest. Then, since you know there are exactly five numbers, the third must be the median.
Your problem then becomes sorting the numbers; finding the median is simple after that's done.
Sorting is a very common task. Try a forum search for some pointers.
Mar 18 '07 #3
arne
315 Recognized Expert Contributor
One way to go about it would be to first sort the numbers from lowest to highest. Then, since you know there are exactly five numbers, the third must be the median.
Your problem then becomes sorting the numbers; finding the median is simple after that's done.
Sorting is a very common task. Try a forum search for some pointers.
Sorting is even so common that the STL contains a function called sort, so you should be able to simply type

Expand|Select|Wrap|Line Numbers
  1. sort( a, a+5 );
  2.  
to sort your array named a with the 5 numbers. Unless you really want to do the sorting by yourself (which is a good exercise!), I would always prefer the STL algorithms.
Mar 18 '07 #4

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

Similar topics

2
by: Bob | last post by:
I have been looking at the code for MedianFind(pDte As String) from the following thread from UtterAccess.com: "Finding Median average grouped by field" I have been able to get it to run using...
8
by: nick.vitone | last post by:
Hi, I'm somewhat of a novice at Access, and I have no experience programming whatsoever. I'm attempting to calculate the statistical median in a query. I need to "Group by" one column and find...
1
by: Jaime Leivers | last post by:
Here's a median function in access that you can call in any query. You could change this to any excel function you wanted. Most people can find the windows help file that says how to call an excel...
12
by: erikcw | last post by:
Hi all, I have a collection of ordered numerical data in a list. The numbers when plotted on a line chart make a low-high-low-high-high-low (random) pattern. I need an algorithm to extract the...
10
by: suhdominic | last post by:
Can anyone help me how to program in C++ which determines the median of five input numbers?
7
by: Bhadan | last post by:
Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.
3
by: mehwishobaid | last post by:
i dont know wat is wrong with my code. when i compile. i get the error saying line 29: error: expression must have pointer-to-object type #include <iostream> using namespace std; #include...
7
by: tomshorts07 | last post by:
hi everyone! i was wondering if anyone had any ideas on how to go about coding a method that would determine the median of a list of numbers just to clarify- a median is the 'middle value' when...
3
by: tkpmep | last post by:
I have coded a robust (Theil-Sen) regression routine which takes as inputs two lists of numbers, x and y, and returns a robust estimate of the slope and intercept of the best robust straight line...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.