Question: Needs to be done in C++. Funciton needs to read card number from right to left int luhnDigitSum(const string& cardNumber) Sums the digits of a

Needs to be done in C++. Funciton needs to read card number from right to leftNeeds to be done in C++. Funciton needs to read card number

int luhnDigitSum(const string& cardNumber)

Sums the digits of a credit card number according to the luhn algorithm. Calling sumOfDigits("79927398713") should result in 70.

This function should make use of charToInt and doubledDigitValue.

Here's charToInt already working fuction below. int charToInt(char digit){ //tested works 100%
 if((digit >= '0' && digit  
 return digit - '0';
 }
 else{
 return -1;
 }
}

Here's doubleDigitValue already working function below.

 int doubleDigitValue (int number){ //tested works 100%
 number = number * 2;
 if (number  
 return number;
 else
 return (number / 10) + (number % 10);
 }
Credit Card Checker Chemeketa CS Given the number79927398713", we would start on the right with the 3- since it is the first digit it would not be doubled. The next digit is 1 - since it is second it would be doubled to make 2. Next is 7 and it is not doubled (since it is third). Then is 8 and it is doubled which makes 16; because 16 is no longer one digit, we would turn it into 7 (1+6) 7 9 7. 9 7 3 9 18 9 2 4 3 6 8 16 7 Digit Doubled Two Digits One Final Digit Value 1 2 Sum 7 9 9 4 7 6 9 7 7 2 3 70 The sum of all the final digit values is 70, which is divisible 10. So that is pos ly a valid credit card. Given the number 12345671234567", we would start on the right with the 7 - it would not be doubled. The next digit is 6-it is doubled, which makes 12 and since that is two digits we turn it into 3(1+2)... 2 4 5 6 1 3 1 2. 6 3 6 5 7 2 4 Digit Doubled Two Digits One Final Digit Value 7 14 5 10 1 4 8 12 3 Sum 2 2 6 4 1 6 5 1 4 3 8 5 3 7 57 This time, the sum of the final digit values is 57, which is not divisible by 10 and thus NOT a possible credit card number

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!