Thread: Calculating the Median

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Calculating the Median

    Hi

    im now trying to work on calculating the mean, were by the array is arranged into size order, and the the median is printed out, i am having problems with the code, the cmd.exe flashes open then shut again, i am not recieving any errors, any ideas. im using visual studio C++ 2010

    Code:
    #include <stdio.h>
    #define Size 11
    int main()
    {
    float median[]={13, 36, 16, 21, 24, 16, 21, 10, 18, 16};
    int x;
    int y;
    float temp;
    int stop;
    
    
    for(x=0; x<Size; x++)
    	{
    		for(y=x+1; y<Size; y++)
    		{
    			if(median[y]>median[x])
    			{
    				temp=median[x];
    				median[x] = median[y];
    				median[y] = temp;
    			}
    		}
    	}
    
    
    	if(Size%2==0)
    	return printf("%f\n",(median[Size/2]+median[Size/2-1])/2);
    	else
    	return printf("%f\n",median[Size/2]);		
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by openwindow
    the cmd.exe flashes open then shut again, i am not recieving any errors, any ideas. im using visual studio C++ 2010
    By default, Visual Studio C++ 2010 should pause the console window for you. Besides changing whatever setting is required, read: Pause console.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Median Help!
    By tidbit in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2010, 09:55 PM
  2. Median filter help
    By JTEK24 in forum Tech Board
    Replies: 10
    Last Post: 07-16-2009, 06:05 PM
  3. Median
    By Neo1 in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2007, 04:00 PM
  4. Median
    By Suchy in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2006, 02:07 AM
  5. median
    By frank in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2001, 04:32 PM