Credit Card Validation Question

Hello,

I have an assignment where I need to write a program to validate a credit card using the LUHN formula (MOD10). I have steps on what to do but I'm lost on the first two.

Step 1: Double the value of alternate digits of the primary account number beginning with the second digit from the right.

Step 2: Add the individual digits comprising the products obtained in Step 1 to each of the unaffected digits in the original number.

I'm not sure how to go about doing either of those two steps. Also note that the 6 credit cards numbers that are being provided I'm reading in from another file. I've got that part its what to do after I get the numbers into my program where I lose it.

Any help would be great!

Thanks in advance!!
Please I need help!!! I feel like I know exactly what needs done but dont know how to implement what I'm thinking!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>

int main()
{
    // get the digit at position pos
    // (counting towards left with the right most digit at position zero)

    const std::size_t pos = 7 ;

    // from a string
    const std::string numstr = "9876543210" ;
    const std::size_t sz = numstr.size() ;
    int digit = pos < sz ? numstr[ sz - 1 - pos ] - '0' : 0 ;
    std::cout << "digit at position " << pos << " from the right is " << digit << '\n' ;

    // from an unsigned long long
    const unsigned long long number = 9876543210 ;
    int divisor = 1 ;
    for( std::size_t i = 0 ; i < pos ; ++i ) divisor *= 10 ;
    digit = ( number / divisor ) % 10 ;
    std::cout << "digit at position " << pos << " from the right is " << digit << '\n' ;
}


Take it up from there.
Topic archived. No new replies allowed.