Just finished working on credit and after testing it with the number in pset1 page it was working well and I have tested it against other numbers too the problem is when I ran check50 it said that
:) credit.c exists.
:) credit.c compiles.
:) identifies 378282246310005 as AMEX
:) identifies 371449635398431 as AMEX
:( identifies 5555555555554444 as MASTERCARD
expected "MASTERCARD\n", not "INVALID\n"
:( identifies 5105105105105100 as MASTERCARD
expected "MASTERCARD\n", not "INVALID\n"
:) identifies 4111111111111111 as VISA
:) identifies 4012888888881881 as VISA
:) identifies 1234567890 as INVALID
:( identifies 369421438430814 as INVALID
expected "INVALID\n", not "VISA\n"
:( identifies 4062901840 as INVALID
expected "INVALID\n", not "VISA\n"
:) identifies 5673598276138003 as INVALID
:) identifies 4111111111111113 as INVALID
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
here is my code: https://pastebin.com/m3JzXXuB
note: sorry for the poor formatting can't get that code block.
1 Answer
Three issues.
First, the code doesn't check the length of the cc number at all. All other criteria could be correct, but if the length is wrong, it's still invalid.
Second, the checksum calculation can be incorrect. There are problems in the calculation:
if (arr[i] * 2 / 10.0 > 1)
What happens when the result is exactly 1, meaning that arr[i]*2 = 10? The test fails and the code skips to the else clause, adding the wrong sum. The outcome is that 10 is added to sum instead of 1.
Third, there's something that you forgot to check for all visa cards. I'll let you figure that one out on your own though. ;-)
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)
-
Thanks. for the visa part I thought since there is no other choice I don't need to check Commented Jul 11, 2018 at 8:30