vendredi 27 mars 2020

IF statement with logical && and || operators

I have the following code:

if (scanf("%d %d %d", &number1, &number2, &number3) == 3 &&
    ((number1 == rndNumber) || (number2 == rndNumber) || (number3 == rndNumber))) {
    printf("Champ!\n");

} else if ((number1 && number2 > rndNumber) || (number1 && number3 > rndNumber) ||
           (number2 && number3 > rndNumber)) {
    printf("else if!\n");
} else {
    printf("else\n");
}

If the rndNumber is for example: 10

and the input for the 3 numbers is: 1, 11, 1 or 1, 1, 11 or 11, 1, 1 or 1, 1, 1

The else statement will only be executed on the third and fourth input..I dont understand why

Aucun commentaire:

Enregistrer un commentaire