# credit.c problem on some input nubers

Here is my final output to credit.c ``````checksum = (checksum / 1) % 10;

if (checksum != 0)
{
printf("INVALID\n");
}

//Validation for American Express
if (count == 15)

{
}

//First Validation for 13 VISA
// gets the last number from 13-digit number
int visa = input / 1000000000000; // = 4
if (count = 13 )
{

if ( )
{

}
else
{

}
}
//Second Validation for VISA
if (count == 16)
{
visa = (ccNumber / 1000000000000000) % 10;
//printf("%d", visa);
if (visa == 4) //
{
printf("VISA\n");
}
//Or else MASTERCARD
else
{
}
}
``````

Case 1: When input is 4062901840

Calculating checksum:

``````                 // 2nd to last digit
4  0  6  2  9  0  1  8  4  0

4*2 + 1*2 + 9*2 + 6*2 + 4*2

8 + 2 + 18 + 12 + 8

8 + 2 + 1 + 8 + 1 + 2 + 8

30

// Remaining digits

0 + 8 + 0 + 2 + 0

10

SO checksum = 10 + 30 = 40
``````

Here checksum has last digit as 0 / checksum = (checksum / 1) % 10 is 0 if (checksum != 0) doesn't run. It expects "INVALID\n" as answer. Since digit count = 10 , none of the condition block runs. So it returns null " ".

Case 2: When input is 4111111111111113

Similarly, checksum results 32. So, condition block if (checksum != 0) runs and prints out "INVALID" Also, when count is 16 condition block if (count == 16) runs as well printing out VISA so final output is INVALID VISA

I don't think writing condition when count = 10 prints INVALID would be much of good logic. And in 2nd case, is there way to stop program after running condition if (checksum != 0) not having to run other part of condition block? How am I doing it wrong? Any feedback is appreciated.

• The program must always produce an output. So program needs to do something, like `printf("INVALID\n");`, when "none of the condition block runs."
• The program should produce exactly one output. Once that output is produced program should terminate, as with `exit;`