I have a code that suppose to prompt a user for thre numbers and output them in ascending order but i get the wrong results for example if i put in 476 it output 764 and i am trying to fix this and add the comments of havigng it prompt for the iputs

#include <iostream>
// for being able to use library functions
using namespace std;
int main()
{
    // declare three variables
    int a,b,c;
    // take inputs from command line
    cin>>a>>b>>c;
    if(a>b && a>c)
    {
        cout<<a<<endl;
        if(b>c)
        {
            cout<<b<<endl;
            cout<<c<<endl;
        }
        else
        {
            cout<<c<<endl;
            cout<<b<<endl;
        }
    }
    else if(b>a && b>c)
    {
        cout<<b<<endl;
        if(a>c)
        {
            cout<<a<<endl;
            cout<<c<<endl;
        }
        else
        {
            cout<<c<<endl;
            cout<<a<<endl;
        }
    }

    else if(c>a && c>b)
    {
        cout<<c<<endl;
        if(b>a)
        {
            cout<<b<<endl;
            cout<<a<<endl;
        }
        else
        {
            cout<<a<<endl;
            cout<<b<<endl;
        }
         cin.get();  // for stopping the window
    cin.ignore(); // from closing
    return 0;
    }
    }
Member Avatar for iamthwee

Any particular reason why you're not using an array?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.