I'm working on Credit and am at the point where I have completed all the required calculations on the credit card and now need to find out if the final sum ends in zero or not. I think that in order to do this I need to first know how long the final number is and then find the last digit using a for loop. However, I don't know how to find the length of the number. My first thought was to store the integer in a string variable and then use strlen on the string, however this seems to be invalid according to error messages I get. Does anyone know how else I can go about doing this?


I took a copy of the number, and in a loop divided the copy by 10 until it was 0 (integer by integer division truncates the result, ignoring any fractional part, the result of such division is integer again). The number of iterations tells you the number of digits, ignoring leading zeroes (which don't exist in credit card numbers).

I have more in that loop, so that after the loop I have a checksum, the number of digits, and the last two digits processed (meaning the first two digits of the credit card number)

You must log in to answer this question.

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