and well im terribly stuck its my 2nd maybe 3rd week of classes and afraid of falling behind if any1 can offer help or a place to look for some advice that would be wonderful
One validation algorithm is the LUHN formula. This formula works as follows:
1. Set the sum to 0
2. Add up the digits in the credit card number, working from right to left:
* If the digit has an odd position, counting from the right, add it to the sum as-is. Thus, the first, third, etc. digits (counting from the right) are all added directly to the sum.
* Otherwise, double the value of the current digit. If it is over 10, add the digits to get a number less than 10. Then add the result to the sum.
3. If the sum divides evenly by 10 (i.e., with a remainder of 0), then the credit card number is valid. Otherwise, the card number is invalid.
For example, consider the (abbreviated and fictional) card number 499673. Doubling alternate digits (4, 9, 7), we get: (4 * 2) + 9 + (9 * 2) + 6 + (7 * 2) + 3
(9 * 2) and (7 * 2) are greater than 10, so we add the digits: (9 * 2) = 18 = (1 + 8) = 9. Doing the same for 7, we get 5. HINT: you can also just subtract 9 from the doubled digit.
The sum of these digits is 40, which divides evenly by 10, so this number is valid.