Multiple conditions in an if

0

I'm having a code here, and I need to put multiple conditions inside an IF.

In case I need to put it this way:

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

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

    
asked by anonymous 20.11.2015 / 20:02

2 answers

4

Use && :

if (X->meia != 's' && X->meia != 'S' && X->meia != 'N' && X->meia != 'n')
{
   printf("\nDigite S ou N!!\n");
}
    
20.11.2015 / 20:26
2

Should be && instead of || .

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

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

    
20.11.2015 / 20:34