I ran compile this:
char get_credit_card_status(long long credit_card_number, char Luhn_validity)//, char credit_card_status)
{
char credit_card_status = 0;
if (((credit_card_number < 350000000000000) && (340000000000000 <=credit_card_number)) && (Luhn_validity=1))
{
credit_card_status = 1;
printf("1 test\n");
}
else if ((5100000000000000<= credit_card_number) && (credit_card_number < 5500000000000000) && Luhn_validity)
{
credit_card_status = 2;
printf("2 test\n");
}
else if ((((4000000000000<= credit_card_number)&&(credit_card_number<5000000000000)) || ((4000000000000000<=credit_card_number)&&(credit_card_number<5000000000000000))) && Luhn_validity)
{
credit_card_status= 3;
printf("3 test\n");
}
return credit_card_status;
}
int length_ccn(long long credit_card_number)
{
int length = 0;
while (credit_card_number > 0)
{
length++;
credit_card_number /= 10 ;
}
return length;
}
char Luhn_check(long long credit_card_number)
{
int total_even_numbers = 0;
int total_odd_numbers = 0;
int even_number = 0;
int odd_number = 0;
int Luhn_sum = 0;
char Luhn_validity = 0;
long long check_digit_basis = credit_card_number;
for(int i =1 ; check_digit_basis > 0 ; i++)
{
if ((i % 2) > 0)
{
odd_number = (check_digit_basis % 10);
total_odd_numbers = total_odd_numbers + odd_number;
}
else
{
even_number = (check_digit_basis % 10);
if(even_number >= 5)
{
total_even_numbers = total_even_numbers + ((( 2 * even_number) % 10) + 1 );
}
else
{
total_even_numbers = total_even_numbers + (2 * even_number);
}
}
check_digit_basis = (check_digit_basis / 10);
}
Luhn_sum = total_even_numbers + total_odd_numbers;
if ((Luhn_sum % 10 ) == 0 )
{
Luhn_validity = 1;
}
else
{
Luhn_validity = 0;
printf("%c for Luhn_validity\n", Luhn_validity);
}
printf("%d for Luhn_validity\n", Luhn_validity);
return Luhn_validity;
}
int main(void)
{
printf("Provide your credit card number:\n");
long long credit_card_number = get_long_long();
int length = length_ccn(credit_card_number);
printf("%i for length\n", length);
char Luhn_validity = Luhn_check(credit_card_number);
printf("%c returned from line 119\n", Luhn_validity);
char credit_card_status;
credit_card_status = get_credit_card_status(credit_card_number, Luhn_validity);
switch (credit_card_status)
{
case 1:
printf("American Express\n");
break;
case 2:
printf("MasterCard\n");
break;
case 3:
printf("Visa\n");
break;
default:
printf("INVALID\n");
}
}
I got:
15 for length
1 for Luhn_validity
returned from line 119
The value of Length
is returned to the main function while Luhn_validity
isn't. Why?
I cannot make another post because someone posted an incomplete answer only answering to what I already began to implement (see the post before its edits and you'll see that the boolean problem was being corrected and wasn't in the post's title).
Can you help me?
Thanks in advance.