why does this happen? I want it so that it does not display the text using an or statement and not using and or anything else.

if( 1 == (2 || 2 || 2))
    {
      cout << "Should not display";
    }

I dont understand this question at all. Can you please rephrase? The code you supplied doesnt make any sense. 1 will never equal 2 or 2 or 2...;)

why does this happen? I want it so that it does not display the text using an or statement and not using and or anything else.

if( 1 == (2 || 2 || 2))
    {
      cout << "Should not display";
    }

If atleast one of the statement is true it will go to the condition.

if ( (x==a) || (x==y) || (x==z) ) { //statement
    cout << "Should not display"; //condition
}
commented: Helpful! +0

I dont understand this question at all. Can you please rephrase? The code you supplied doesnt make any sense. 1 will never equal 2 or 2 or 2...;)

Yes!!! exactly! but when I compile it. it prints out that message. I don't that phrase to show.

If atleast one of the statement is true it will go to the condition.

if ( (x==a) || (x==y) || (x==z) ) { //statement
    cout << "Should not display"; //condition
}

ahhh Thank you :D.

The result of the || operator will be either 0 or 1.

Let's walk through this:

if ( 1 == (2 || 2 || 2) )
if ( 1 == (1 || 2) )
if ( 1 == 1 )
if ( 1 )

So your condition is always true.

But it appears you've already got the correct wording for what you intended.

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.