dimanche 28 juin 2020

If condition doesn't output properly yet it compiles in C

So it compiles ok, but the output it is not the expected. The issue I think is in the OR operator which does not work properly, or it conflicts with the && operator. But perhaps it's bad written or something. Please let me know. Thanks in advance.

Here's the code:

if((len == 16) && secDigit == (51 | 52 | 53 | 54 | 55)
{
    printf("MASTERCARD\n");
    exit(0);
}

else if((len == 15) && secDigit == (34 | 37))
{
    printf("AMEX\n");
    exit(0);

}

else if((len == (16 | 13)) && firstDigit == 4)
{
    printf("VISA\n");
    exit(0);
}

else
{
    printf("INVALID\n");
    exit(0);
}

Aucun commentaire:

Enregistrer un commentaire