Hello I'm currently coding something for class. We are basically making a credit card checker to pull the numbers from a text file. The rules we have to follow for the check digit are the following.
Drop the last digit from the card number. The last digit is the check digit.
Reverse the digits.
Multiply the digits in odd positions (1, 3, 5, etc.) by 2.
Subtract 9 from any result higher than 9.
Sum all the digits.
The check digit (the last number of the card) is the amount that you would need to add to get a multiple of 10 (Modulo 10)
So I pulled the check digit away by setting a new variable and taking the card # /10. It's in a long so no decimals so this gets rid of the last digit. I then stored that digit as my check digit using %10 of the original number. I then used a loop to reverse the digits which can be seen as:
long lcards = Long.parseLong(cards);
long lastDigit = lcards % 10;
long newCard = lcards / 10;
long reverseCard = 0;
while (newCard != 0)
{
reverseCard = reverseCard * 10;
reverseCard = reverseCard + (newCard % 10);
newCard = newCard / 10;
}
I'm now stuck on the next step :/. How would I do this? Thanks!