Multiple conditions on an if

Asked

Viewed 12,933 times

0

I have a code here, and I need to put several conditions within an IF.

In case I need to put it that way:

if (X->meia != 's' || X->meia != 'S' || X->meia != 'N' || X->meia != 'n')
{
   printf("\nDigite S ou N!!\n");
}

But that way the condition is not working. How do I?

2 answers

4

Use &&:

if (X->meia != 's' && X->meia != 'S' && X->meia != 'N' && X->meia != 'n')
{
   printf("\nDigite S ou N!!\n");
}

2

Should be && instead of ||.

If the bars were true, one condition would be true to print the message. That is, if meia for a n the message is printed because n != s.

If it were the && it is necessary that they all be true for the Mastermind to be printable, that is, the character not to be n or s.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.