I've just done "credit" task and it can't pass automated check by "check50 2016.credit credit.c" despite it passes manual check very well (I showed it below). I also add my code just in case. I have no idea what am I doing wrong so any help would be appreciated. Thanks.

Here is my code:

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

#define EVEN    1
#define ODD 0

int main(void) {
int pt1, pt2, n, c, i, valinp;
int v, m, a;
int dig[100];
int cit = EVEN;

do {
pt1 = 0, pt2 = 0, valinp = 1;
for (n = 0; (c = getchar()) != EOF && c != '\n'; n++) {
if (c < 48 || c > 57)
valinp = 0;
c -= 48;
dig[n] = c;
}
if (n == 0)
valinp = 0;
} while (valinp == 0);

// AMEX_identify
if (dig[0] == 3 && (dig[1] == 4 || dig[1] == 7))
a = 1;
else
a = 0;

// Master_identify
if (dig[0] == 5 && (dig[1] == 1 || dig[1] == 2 ||
dig[1] == 3 || dig[1] == 4 || dig[1] == 5))
m = 1;
else
m = 0;

// Visa_identify
if (dig[0] == 4)
v = 1;
else
v = 0;
//
for (i = (n - 1); i >= 0; i--) {
if (!cit) {
pt2 += ((dig[i] * 2) / 10 + (dig[i] * 2) % 10);
cit = EVEN;
} else {
pt1 += dig[i];
cit = ODD;
}
}

if (((pt1 + pt2) % 10) == 0) {
if (v && (n == 13 || n == 16))
printf("VISA\n");
else if (a && n == 15)
printf("AMEX\n");
else if (m && n == 16)
printf("MASTERCARD\n");
else
printf("INVALID\n");
}
else
printf("INVALID\n");

return 0;
``````

}

One of the hidden lessons in the first few psets is to write to the specification exactly. That means that anything extra, missing or misplaced, including prompts, output, whitespace, line feeds, comments, etc., will cause a fail, particularly with the automated grader check50.

With that in mind, let's look at an example of your output:

``````\$ ./credit
378282246310005
AMEX
``````

and the example from the program spec:

``````\$ ./credit
Number: 378282246310005
AMEX
``````

What's different?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

• Thank you. Printing of textual prompt really helped. Jun 20 '17 at 3:55
• I just don't understand why I have to print any text before entering card number, The task says "...write a program that prompts the user for a credit card number..." (nothing about pre-printing) and "...we ask that your program’s last line of output be AMEX\n or MASTERCARD\n or VISA\n or INVALID\n, nothing more, nothing less..." (so as my programm outputs). Yesterday I spent whole day trying to fix this, tried several ways to solve this but I could'n even imagine that solution for this is so simple))))). Thank you, Cliff. Jun 20 '17 at 4:34