0

Here's my code-

  
    int f_1 = floor(N / 1000000000000000);
    int f_2 = floor(N / 1000000000000);
    int f_3 = floor(N / 100000000000000);
    int f_4 = floor(N / 10000000000000);
    
    if (moddigitsum_total != 0)
    {
        printf("INVALID\n");
    }
    
    else if (moddigitsum_total == 0)
    {
        if ((countdigit == 13 || countdigit == 16) && ((f_1 == 4) || (f_2== 4))) 
        {
            printf("VISA\n");
            
        }
        
        
        if ((countdigit == 16) && ( (f_3 == 51) || (f_3 == 52) || (f_3 == 53) || (f_3 == 54) || (f_3 == 55)))
        {
            printf("MASTERCARD\n");
             
        }
       
        
        if ((countdigit == 15) && ((f_4 ==  34) || (f_4 == 37))) 
        {
            printf("AMEX\n");
              
        }
        
        else if((countdigit != 13 && countdigit != 16 && countdigit != 15) && ((f_1 != 4) && (f_2 != 4) && (f_3 != 51) && (f_3 != 52) && (f_3 != 53) && (f_3 != 54) && (f_3 != 55) && (f_4 == 34) && (f_4 != 37)) )
        {
        printf("INVALID\n");
        }
      
    }

I found this error when 2 numbers starting with 56 & 36 were yielding Mastercard & Amex respectively while the output should have been INVALID. Why is it happening? Am I using wrong operators inside if statement? or is my grouping of booleen ecpressions wrong?

0

Check the last else if condition. According to your code, if the number of digits is invalid AND the first few digits don't match only then it will print invalid. Thus, if either the number of digits is correct, or the first few digits are correct, then condition will be false and invalid will not be printed! So you need to correct that condition first!

If you can post the rest of your code I'll be able to help with the other errors as well. At least you should post the function definitions of f_1, f_2, f_3 & f_4.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .