Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 left
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' && digitreturn digit - '0';}else{return -1;}}Here's doubleDigitValue already working function below.
int doubleDigitValue (int number){ //tested works 100%number = number * 2;if (numberreturn number;elsereturn (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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started