0

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";
    }
4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Dave Sinkula
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...;)

1

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
}
Votes + Comments
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.

0

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.