It was said that you can verify if the credit card number is valid by using Luhn’s algorithm. If you done mathematical operations right, after them, you know if the card is valid if the last digit in the sum is a 0.
So I was checking for that of course, beside starting numbers and car number length. But check50 said my code is wrong. I would get this message:
~/workspace/pset1/ $ check50 2016.credit credit.c
:) credit.c exists
:) credit.c compiles
:( identifies 378282246310005 as AMEX
\ expected output, but not "INVALID\n"
:( identifies 371449635398431 as AMEX
\ expected output, but not "INVALID\n"
:( identifies 5555555555554444 as MASTERCARD
\ expected output, but not "INVALID\n"
:( identifies 5105105105105100 as MASTERCARD
\ expected output, but not "INVALID\n"
:( identifies 4111111111111111 as VISA
\ expected output, but not "INVALID\n"
:( identifies 4012888888881881 as VISA
\ expected output, but not "INVALID\n"
:) identifies 1234567890 as INVALID
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
I was sure it is right, because I tested with this imaginary number 4000000001040, which is valid according to Luhn's algorithm and it works. Then I decided to remove check for Luhn’s algorithm, just that, I compiled it again and it worked fine. Everything was valid after check50.
So I wanted to see what is going on there. I took one number (371449635398431) form check50 output and done the math according to Luhn's algorithm. The result was 107, and by that it was invalid by Luhn's algorithm. Only if it end with 0 it is valid.
So, it's normal to get INVALID as output. But cs50 check50 says it should be valid AMEX card.
So, I am asking here. Am I wrong or what? Should I use Luhn's algorithm to check for validation?