apartmenthaa.blogg.se

C program for luhn algorithm
C program for luhn algorithm




Then, I usually have some good template I can use to write it in a less powerful language such as C. Here is what I usually do if I "try to implement" something I am not sure about: I use an interactive language, such as Common Lisp, tinker and test interactively until it works. Then, the last line will check the rightmost digit of the current tsum and will tell me if the card is valid according to Luhn's Algorithm. Then starting from the 2nd rightmost digit, the digit is multiplied by 2 then added to tsum, with every other digit doing the same. I would also like to add, in my mind what this code should do is: using the checks for even and odd it will start from the rightmost digit and add it to tsum, every other digit will do the same.

c program for luhn algorithm c program for luhn algorithm

And I am expecitng a value of 0 for tsum when inputting any card number from Paypal's Standard Test Cards. I would appreciate somebody to tell me what I'm doing wrong, thank you.ĮDIT: Apologies, cardNum is a long long. I have spent hours trying to troubleshoot and find the issue, count represents the number of digits in the card number, the rest define themselves. Luhn's Algorithmįor (int tempcount = count tempcount > 0 tempcount-) So, I'm trying to make Luhn's algorithm in C, but it doesn't return the correct values when running it.






C program for luhn algorithm