Thread: swaping numbers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    14

    swaping numbers

    I am trying to put three numbers in order from smallest to largest by swaping them. I can figure out how to get all of them to display after they are swapped. Any help would be great.
    Code:
    void swap2(double a, double b)
    {	
    	double temp = a;
    	a = b;
    	b = temp;
    }
    
    int main()
    {
    	double a, b, c;	
    	cout<<"Enter three numbers.";						
    	cout<<endl;				
    	cin>>a >>b >>c;				
    	cout<<endl;			
    		
    	if (a < b && a < c)					
    	{
    			
             	cout<<a;	 
    	cout<<endl;							
    	}
    
    	else if (b < c)
    	{
    		cout<<b;
    		cout<<endl;
    	}
    	
    	else 
    	{
    		swap2(b,c);
    		cout<<c
    		cout<<endl;
    		cout<<b;
    		cout<<endl;
    	}
    
    return 0;
    }
    Last edited by bj31t; 03-29-2004 at 04:46 PM. Reason: code tags

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about random numbers
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 07-02-2008, 06:28 AM
  2. Comparing numbers to a list of numbers held in a text file
    By jmajeremy in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2006, 07:56 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM