THis is about c programming (CS50 HArvard course PSET 1 Hacker) The goal is to find if a credit card number is valid. Complete Instructions Here:...

THis is about c programming (CS50 HArvard course PSET 1 Hacker) The goal is to find if a credit card number is valid. Complete Instructions Here: https://cdn.cs50.net/2015/x/psets/1/hacker1/hacker1.html#bad_credit Can I please know what makes my code fail? (I dont get running errors) My code: #include #include #include #include #include #include int main(void) { char name[20]; char dist[3]; long long number = GetLongLong(); sprintf(name, "%lld", number ); int length = strlen(name); if ( (length != 13) || (length != 15) || (length != 16) ) { printf("INVALID"); return 1; } int SUM = 0; if ( (length == 13) || (length == 15) ) { for (int a = 1; a { int prodig = (name[a]-48)* 2; sprintf(dist, "%d", prodig); if (strlen(dist) == 2) { SUM = SUM + (dist[0]-48) + (dist[1]-48); } else { SUM += prodig; } } for (int a = 0; a { SUM += (name[a]-48); } } if (length == 16) { for (int a = 1; a { int prodig = (name[a]-48)* 2; sprintf(dist, "%d", prodig); if (strlen(dist) == 2) { SUM = SUM + (dist[0]-48) + (dist[1]-48); } else { SUM += prodig; } } for (int a = 0; a { SUM += (name[a]-48); } } if (SUM%10 != 0) { printf("INVALID"); return 1; } else { if (name[0] == 3) { printf("AMEX"); } else if (name[0] == 5) { printf("MASTERCARD"); } else { printf("VISA"); } } return 0; } Output of test (on cs50 site): $ check50 2015.fall.hacker1.credit credit.c :) credit.c exists :) credit.c compiles :( identifies 378282246310005 as AMEX \ expected output, not a prompt for input :( identifies 371449635398431 as AMEX \ expected output, not a prompt for input :( identifies 5555555555554444 as MASTERCARD \ expected output, not a prompt for input :( identifies 5105105105105100 as MASTERCARD \ expected output, not a prompt for input :( identifies 4111111111111111 as VISA \ expected output, not a prompt for input :( identifies 4012888888881881 as VISA \ expected output, not a prompt for input :( identifies 1234567890 as INVALID \ expected output, not a prompt for input :( rejects a non-numeric input of "foo" \ expected output, not a prompt for input :( rejects a non-numeric input of "" \ expected output, not a prompt for input
Nov 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here