Luhn Algorithm in C++
Doubling the even digits and subtracting 9 if > 10 would be mod 9 so a really simple, compact algorithm might be:

for (int i = 0; i &lt; nDigits; i++)
{
    int   digit = digitArray [i] - '0';   // Char to number
    if  (i &amp; 1)  // Digit 1, 3, 5 not 0, 2, 4 - "even digits" starting at 1
        if  ((digit &lt;&lt;= 1) &gt;= 10) //  Double it, check &gt;= 10
            digit -= 9;           //  Same as summing the digits
    shuma += digit;
}
int checksum = shuma % 10;