Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 16th, 2007, 11:36 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help! mean program

okay, so, im supposed write a program that gives the mean of three numbers. Problem is, i have no idea what im doing. The program doesnt compile and i dont know if i'm even doing this right.

any help would be greatly appreciated


// This program uses functional decomposition to determine the median // of three input numbers. The user can input the values in any order, // the program determines which value is between the other two.


#include <iostream>
#include <cstdlib>




using namespace std;
int main()

{
int firstNum;
int secondNum;
int thirdNum;
int medianIs;

cout<<"Enter three numbers";
cin>>firstNum>>secondNum>>thirdNum;
cin.ignore();



    if (firstNum <=secondNum)
    if (secondNum<=thirdNum)
        medianIs=secondNum;{
        }cout<<"The Median is"<<secondNum;

}

     else
     if(firstNum<=thirdNum)
     medianIs=thirdNum{
     cout<<"The Median is"<<thirdNum;

}

    else
    medianIs=firstNum;{
       cout<<"The Median is"<<firstNum;
}


    if (thirdnum<=secondNum)

        medianIs = secondNum;{
        cout<<"The Median is"<<secondNum;
}
    if(firstNumb<=thirdNum)
     medianIs=firstNum
     medianIs=thirdNum;



 return 0 ;
}


Reply With Quote
  #2 (permalink)  
Old March 16th, 2007, 11:38 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thats median and not mean, i was previously looking at a post that was median, sorry.

Reply With Quote
  #3 (permalink)  
Old March 19th, 2007, 06:17 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

So you figured out your problem or you need a help findinig the mean?

mean is just adding them all together and dividing by the number of values you added...

very simple

~ Geo

~ Don't take life too seriously, you'll never get out alive!
Reply With Quote
  #4 (permalink)  
Old March 19th, 2007, 06:17 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well...
If you want mean then - what Geo said.
If you want median - let me explain it to you for any number of numbers, not just 3.

Sort the numbers in ascending or decending order. Then pick the "middle" element.
If it is an even no. of numbers then there are two medians (the two middle elements).

Code:
#include<iostream>
using namespace std;
void main()
{
    int size, median, med1, med2, temp;

    cout<<"How many numbers?";
    cin>>size;
    const int S = size;
[s]   int *array=new int ;

    cout<<"Enter the list of numbers: ";
    for(i=0; i<size; i++)
        cin>>array[i];


//Now to sort them (using simple bubble sort)
    for(int i=0; i<size; i++)
        for(int j=0; j<size; j++)
        {
            if(array[i]>=array[j])
            {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }

//For odd no. of elements (like 3,7,11 etc)
    if (!size%2)
    {
        median = array[(size+1)/2 - 1];
        cout<<endl <<"Median is :" <<median;
    }

//For even no. of elements
    else
    {
        med1 = array[size/2];
        med2 = array[size/2 - 1];
        cout<<endl <<"Median 1 is: " <<med1 <<endl;
        cout<<"Median 2 is: " <<med2 <<endl;
    }
}
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to use for c# Doom C# 2005 2 January 4th, 2008 04:52 AM
What Program manih Assembly Language 1 December 1st, 2006 04:48 PM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 02:08 AM
need help with a program captlem66 C++ Programming 2 October 16th, 2004 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.