Hi!! i am new to C++. Can anyone help me to understand this code please...
I can't really get it.....
like these: && , endl. What these do and what do they stand for??

#include <iostream>
using namespace std;

int main ()
{
    int a,b,c;

    cout<<"Enter three integers :";
    cin>>a>>b>>c;


cout<<endl;
    if (a>b && b>c) {
    cout<<c<<" "<<b<<" "<<a;
    }

    else if (a>c && c>b)
    cout<<b<<" "<<c<<" "<<a;

    else if (b>a && a>c)
    cout<<c<<" "<<a<<" "<<b;

    else if (b>c && c>a)
    cout<<a<<" "<<c<<" "<<b;

    else if (c>a && a>b)
    cout<<b<<" "<<a<<" "<<c;

    else cout<<a<<" "<<b<<" "<<c;

cout<<endl;

    if (a>b && b>c) {
    cout<<a<<" "<<b<<" "<<c;
    }

    else if (a>c && c>b)
    cout<<a<<" "<<c<<" "<<b;

    else if (b>a && a>c)
    cout<<b<<" "<<a<<" "<<c;

    else if (b>c && c>a)
    cout<<b<<" "<<c<<" "<<a;

    else if (c>a && a>b)
    cout<<c<<" "<<a<<" "<<b;

    else cout<<c<<" "<<b<<" "<<a;
}

Recommended Answers

All 3 Replies

if (a>b && b>c) {
    cout<<c<<" "<<b<<" "<<a;
    }

If a>b equates to true and b>c equates to true, the cout will be called. If either do not then cout will not be called. A logical AND operator.
& on its own is a bitwise AND operator.

endl means end line character.

Here this page might help with your question and perhaps some more down the line:
Click Here

As Suzie999 stated, && is use like this: if a is greater than b AND b is greater than c; print c, print b, print a
the "cin" line above the if statement prompts for user input for a, then b, then c. The if statement then compares each set on each side of the && (AND) operator.

endl literally means "end line", at least as far as I know. It tells the compiler that the line of code it is on has ended, and next output or print should be on the next output line.
I hope that my explanation is clear enough.

Thanx Suzie999 and TObannion.....
your comments were very helpful....

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.