Consider:
#include <cs50.h>
#include <stdio.h>
int main (void)
{
//User's Input
long n = get_long("Number: ");
int sum_of_odds = 0;
int sum_of_evens = 0;
int count = 0;
int digit;
long temp = n;
//Computation of numbers(Luhn’s Algorithm)
for (count = 0; temp == 0; count++)
{
digit = temp % 10;
temp /= 10;
if (count % 2 == 0)
{
sum_of_odds += digit;
}
else
{
digit *= 2;
if (digit >= 10)
{
sum_of_evens += digit - 10 + 1;
}
else
{
sum_of_evens += digit;
}
}
}
int start;
//Validity
if ((sum_of_odds + sum_of_evens) % 10 == 0)
{
if (count == 15)
{
start = n / 10^13;
if (start == 34 || n == 37)
{
printf("AMEX\n");
}
else
{
printf("INVALID\n");
}
}
else if (count == 16)
{
start = n / 10^14;
if (start == 51 || start == 52 || start == 53 || start == 54 || start == 55)
{
printf("MASTERCARD\n");
}
else if (start / 10 == 4)
{
printf("VISA\n");
}
else
{
printf("INVALID\n");
}
}
else if (count == 13)
{
start = n / 10^12;
if (start == 4)
{
printf("VISA\n");
}
else
{
printf("INVALID\n");
}
}
else
{
printf("INVALID\n");
}
}
else
{
printf("INVALID\n");
}
}
I seem to have messed up in summing up under Luhn's algorithm as I tested and printed out a sum of 0 after the computation. How can I identify the errors I made?