Im trying to get the sum with Luhn's algorithm with this credit card number: 4003600000000014
I'm getting this output: Sum single numbers: 4195600 Multiplied numbers: 0
I'm trying to get 13 and 7...
Appreciate some help!
#include <stdio.h>
int main(void)
{
do
{
long card_number = get_long("Write your card's number:");
} while (card_number < 0);
// Sum of numbers that wont be multiplied by two
int non_mult_numbers = card_number;
while (non_mult_numbers > 0)
{
int last_digit = non_mult_numbers % 10;
int sum_non_mult_numbers = sum_non_mult_numbers + last_digit;
non_mult_numbers = non_mult_numbers / 100;
}
printf("Sum single numbers: %i\n", sum_non_mult_numbers);
// Sum of numbers that will be multiplied by two and their digits added
int mult_numbers = card_number;
mult_numbers = mult_numbers / 10;
while (mult_numbers > 0)
{
last_digit = mult_numbers % 10;
int digit_times_two = last_digit * 2;
int add_digits = add_digits + digit_times_two % 10 + digit_times_two / 10;
mult_numbers = mult_numbers / 100;
}
printf("Multiplied numbers: %i\n", add_digits);
}