this is the message
identifies 4111111111111113 as INVALID
expected EOF, not "INVALID"
this is the code
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
bool checksum(string credit);
int main()
{
long long cardnumber = 0;
long long calc[1];
string credit;
string lengthkey[1];
//user input
do
{
credit = get_string("Card number: ");
}
while ((credit <= 0));
//to check if condition works
//printf("%s credit\n", credit);
//the long long version of user's string input
//cardnumber = strtoll(credit, NULL, 10);
//copy of long long for calculation
///calc[0] = cardnumber;
//string for address and length
lengthkey[0] = credit;
//printf("%s length\n", lengthkey[0]);
if ((strlen(lengthkey[0]) == 15) || (strlen(lengthkey[0]) == 16) || (strlen(lengthkey[0]) == 13))
{//amex
if (strlen(lengthkey[0]) == 15)
{
if ((lengthkey[0][0] - '0') == 3 && ((lengthkey[0][1] - '0') == 4 || (lengthkey[0][1] - '0') == 7))
{
if(checksum(credit))
printf("AMEX\n");
}
else
printf("INVALID\n");
}
//master card
if (strlen(lengthkey[0]) == 16)
{
if ((lengthkey[0][0] - '0') == 5 && ((lengthkey[0][1] - '0') == 1 || (lengthkey[0][1] - '0') == 2 || (lengthkey[0][1] - '0') == 3 || (lengthkey[0][1] - '0') == 4 || (lengthkey[0][1] - '0') == 5))
{
if(checksum(credit))
printf("MASTERCARD\n");
}
else
printf("INVALID\n");
}
//visa
if (strlen(lengthkey[0]) == 13 || strlen(lengthkey[0]) == 16)
{
if ((lengthkey[0][0] - '0') == 4)
{
if(checksum(credit))
printf("VISA\n");
else
printf("INVALID\n");
}
}
}
//invalid
else
{
printf("INVALID\n");
//369421438430814, 5673598276138003, 4111111111111113, 4222222222223
}
}
//luhn's algorithm
bool checksum (string credit)
{
//calc[0] = cardnumber;
string checksumarray[1];
checksumarray[0]= credit;
long long mult, remaining, firstnumsum = 0, sum_of_even = 0, finalsum;
int a = strlen(checksumarray[0]);
//sum the odd digits
for (int x = a - 1; x >= 0; x -= 2)
{
firstnumsum = firstnumsum + (checksumarray[0][x] - '0');
}
//sum of even digits
for (int j = a - 2; j >= 0; j -=2)
{
mult = 2 * (checksumarray[0][j] - '0');
for (; mult > 0; )
{
remaining = mult % 10;
sum_of_even += remaining;
mult /= 10;
}
}
finalsum = firstnumsum + sum_of_even;
if (finalsum % 10 == 0)
return true;
else
return false;
}