473,411 Members | 2,093 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,411 software developers and data experts.

Finding the Median of 5 numbers

1
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 6994
I too, am interested in finding the answer... any ideas?
Mar 18 '07 #2
scruggsy
147 100+
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 Expert 100+
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
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?
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.