0

I was hoping to use a switch statement for the printf("CARD_NAME"); part of my code, and was wondering if it was bad style/practice to use ... like below? The examples from class all show to use case single_variable:.

switch (check) { 
    case 34 ... 37: 
        printf("AMEX\n");
        break;
    case 51 ... 55:
        printf("MASTERCARD\n");
        break;`
-1

Better use if statements for checking whether a value is within a specific range. switch statements are usually used when there's a number of constant cases that you wanna check your value against them.

if (x >= 34 && x <= 37)
{
    // do something
}
else if (x >= 52 && x <= 55)
{
    // do something
}

You must log in to answer this question.