1

So, I have gotten rid of all the errors and got the code to the point to prompt the user for the credit card number and output an answer the only problem is the program falls thru to invalid every time and never prints a credit card brand. The updated code is posted below any help is appreciated.

Thank you,

include

include

include

include

long checklength(); long checksum(); long cardBrand(long askPositiveLong, long checklength, long checksum);

int main() { long positiveLong = 0; int ccn = 0; long askPositiveLong; do { askPositiveLong = get_long("Enter valid credit card # "); }while(askPositiveLong < 0); printf("%li\n", cardBrand(ccn, positiveLong, askPositiveLong)); }

long checklength(ccn) { if(ccn == 13 || ccn == 15 || ccn == 16) {

    return true;
    return false;
}
return ccn;   

}

long checksum(positiveLong) { int sum = 0; for(int i = 0; i > positiveLong; i++) { if (i % 10 == 0) { int digit = (2*(positiveLong%10)); sum += (digit/10 + digit%10);

    }
    else
    {
    sum += (18/10 == 1) + (18%10 == 8);
    }
}
if(sum % 10 == 0)
{
return true;
return false;
}
return positiveLong;

} long cardBrand (long askPositiveLong, long checklength, long checksum) { if (askPositiveLong >= 340000000000000 && askPositiveLong < 350000000000000) { printf("AMEX\n"); } else if (askPositiveLong >= 370000000000000 && askPositiveLong < 380000000000000) { printf("AMEX\n"); } else if (askPositiveLong >= 5100000000000000 && askPositiveLong < 5600000000000000) { printf("MASTERCARD\n"); } else if (askPositiveLong >= 4000000000000 && askPositiveLong < 4100000000000) { printf("VISA\n"); } else if (askPositiveLong >= 4000000000000000 && askPositiveLong < 4100000000000000) { printf("VISA\n"); } else { printf("INVALID"); } return askPositiveLong; }

| |
  • Please edit the question to format the code. Choose the edit button under the question, select the code, hit the {} in the format bar et voilà. – DinoCoderSaurus Apr 15 at 11:27
  • I couldn't wait for that. ;-) – Cliff B Apr 16 at 5:21
1

Look at the line in question:

if(askPositiveLong >= 340000000000000 && askPositiveLong < 350000000000000)
   || (askPositiveLong >= 370000000000000 && askPositiveLong < 380000000000000)

How are the parentheses???? Anything missing?

I wonder if this problem exists anywhere else??? ;-)

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

| improve this answer | |
  • Thank you, I got rid of the or operators and just added another else if statement for the statements that had or operators in them. The code compiled. – Keith Apr 18 at 3:12
  • That's one way. You could also have just added the missing set of parentheses around everything. – Cliff B Apr 18 at 3:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .