# I can't get the Luhn algorithm to run properly in my code

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

int main(void)
{
long long cardnumber = 0;

//Prompt the user for the credit card number using get_long
do
{
cardnumber = get_long_long("Number: ");
}
while (cardnumber <= 0);

//Running the algorithm to determine validity
long workingCCN = cardnumber;
int sum;

while (workingCCN > 0)
{
int lastdigit = workingCCN % 10;
sum = sum + lastdigit;
workingCCN = workingCCN / 100;
}
workingCCN = cardnumber / 10;
while (workingCCN > 0)
{
int lastdigit = workingCCN % 10;
int timestwo = lastdigit * 2;
sum = sum + (timestwo % 10) + (timestwo / 10);
workingCCN = workingCCN / 100;
}
//Determining the brand

{
if ((cardnumber >= 34e13 && cardnumber < 35e13) || (cardnumber >= 37e13 && cardnumber < 38e13))
{
printf("AMEX\n");
}
else if (cardnumber >= 51e14 && cardnumber < 56e14)
{
printf("MASTERCARD\n");
}
else if ((cardnumber >= 4e12 && cardnumber < 5e12) || (cardnumber >= 4e15 && cardnumber < 5e15))
{
printf("VISA\n");
}
else
{
printf("INVALID\n");
}
}
}
``````
• What is the missing code? There must be some conditional or loop structur to enter the "Determining the brand" block. May 22 '20 at 20:17
• would it be effective to use a condition such as if (cardnumber >= 0) to start the loop? thank you for looking at my code it is much appreciated. May 23 '20 at 12:03
• Also I can't figure out how to say if the last digit of the result of running the algorithm isn't 0 then INVALID. would that be a seperate while loop? May 23 '20 at 12:13