Method for Cedit card check, help!!!!1
2. Write a program to determine whether an input credit number is valid according to the Luhn check. Prompt the user for a credit card number as a long integer and display whether the number is valid.
Need help creating a method for this process, im unsure how to check a set of long numbers and iterate the steps. Please help me with.........
The Luhn check is performed as follows:
Step 1: Double every second digit from the right to the left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number.
Step 2: Now add all single-digit numbers from Step 1.
Step 3: Add all the digits in the odd places from right to left in the card number.
Step 4: Sum the results from Step 2 and Step 3.
Step 5: If the result from Step 4 is divisible by 10, the card number is valid; otherwise it is invalid.
Re: Method for Cedit card check, help!!!!1
What exactly do you need help with (what have you done)?
Re: Method for Cedit card check, help!!!!1
I take it this is an assignment, however if its not, how about Validator - Commons Validator
// Json
Re: Method for Cedit card check, help!!!!1
My first question would be, can a credit card number start with a zero?
If so, you need to capture it as a string rather than a long.
Second of all I'd suggest you use a string anyway and loop through each caracter and extract ever odd one and sum them up.
// Json
Re: Method for Cedit card check, help!!!!1
can you show me an example my professor has not covered that material yet...
Re: Method for Cedit card check, help!!!!1
Here's one way to see if a number is even or odd.
Code :
if (n % 2 == 0)
// n is even
else
// in is odd