# Output problem credit

Finished my credit problem, whit the code below, but when I check it with `check50` everything fails despite the output on the terminal being correct when I check manually.

Code:

``````#include <cs50.h>
#include <stdio.h>

long get_credit_card_nb(void)
{
long    nb;

nb = 0;
while (nb < 1)
nb = get_long("Number: ");
return (nb);
}

int get_cc_len(long cc)
{
int len;

len = 0;
while (cc > 0)
{
cc /= 10;
len++;
}
return (len);
}

int check_cc_len(int len)
{
if (len != 13 && len != 15 && len != 16)
{
printf("INVALID\n");
return (0);
}
}

int check_sum(long cc)
{
int d1;
int d2;
int mod1;
int mod2;
int sum1;
int sum2;

sum1 = 0;
sum2 = 0;
while (cc > 0)
{
// Remove last digit and add to sum1
mod1 = cc % 10;
cc /= 10;
sum1 += mod1;

// Remove second last digit
mod2 =  cc % 10;
cc /= 10;

// Double second last digit and add digits to sum2
mod2 *=  2;
d1 = mod2 % 10;
d2 = mod2 / 10;
sum2 += d1 + d2;
}
return (sum1 + sum2);
}

int get_start_digits(long cc)
{
while (cc > 100)
cc /= 10;
return (cc);
}

int main(void)
{
int     len;
int     total;
int     start_digits;
long    credit_card;

credit_card = get_credit_card_nb();
len = get_cc_len(credit_card);
if (!check_cc_len(len))
return (0);
else
{
total = check_sum(credit_card);
if (total % 10 != 0)
{
printf("INVALID\n");
return (0);
}
start_digits = get_start_digits(credit_card);
if ((start_digits / 10 == 5) &&
(0 < start_digits % 10 && start_digits % 10 < 6))
printf("MASTERCARD\n");
else if ((start_digits / 10 == 3) &&
(start_digits % 10 == 4 || start_digits % 10 == 7))
printf("AMEX\n");
else if (start_digits / 10 == 4)
printf("VISA\n");
else
printf("INVALID\n");
}
return (0);
}
``````

check50

``````:) credit.c exists
:) credit.c compiles
:( identifies 378282246310005 as AMEX
expected "AMEX\n", not ""
:( identifies 371449635398431 as AMEX
expected "AMEX\n", not ""
:( identifies 5555555555554444 as MASTERCARD
expected "MASTERCARD\n", not ""
:( identifies 5105105105105100 as MASTERCARD
expected "MASTERCARD\n", not ""
:( identifies 4111111111111111 as VISA
expected "VISA\n", not ""
:( identifies 4012888888881881 as VISA
expected "VISA\n", not ""
:( identifies 4222222222222 as VISA
expected "VISA\n", not ""
:) identifies 1234567890 as INVALID
:( identifies 369421438430814 as INVALID
expected "INVALID\n", not ""
:) identifies 4062901840 as INVALID
:( identifies 5673598276138003 as INVALID
expected "INVALID\n", not ""
:( identifies 4111111111111113 as INVALID
expected "INVALID\n", not ""
:( identifies 4222222222223 as INVALID
expected "INVALID\n", not ""
To see the results in your browser go to https://submit.cs50.io/check50/180b26efe4f3302c8178cab39eb27048ed3d187b
``````

Someone can point what is wrong withthe output?

• I could change the way I get the input, getting rid of the loop `get_credit_card_nb(void)` since `get_long()` treats it, but the ending result is the same. I really do not understand what I am missing here. I receive the input and validate its size, checksum, first digits... but at the end `check50` always marks it as wrong. Nov 12, 2022 at 18:55