Question: bool is Valid(const string& cardNumber) Returns true/false indicating if the credit card number is potentially a valid number according to the luhn algorithm. This should

bool is Valid(const string& cardNumber)

Returns true/false indicating if the credit card number is potentially a valid number according to the luhn algorithm. This should use a call to luhnDigitSum and not reimplement the logic of that function.

Here's a copy of luhnDigitSum(const string& cardNumber) please only use luhnDigitSum(const string& cardNumber) in main.

 int luhnDigitSum(const string& cardNumber){
 int sum=0;
 for(int i=cardNumber.size()-2 ; i>=0; i=i-2){
 if( charToInt(cardNumber[i]) == -1 ){
 return 0;
 }
 sum = sum + doubleDigitValue(charToInt(cardNumber[i]));
 }
 for(int i=cardNumber.size()-1 ; i>=0; i=i-2){
 if( charToInt(cardNumber[i]) == -1 ){
 return 0;
 }
 sum = sum + charToInt(cardNumber[i]);
 }
 return sum;
 }

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!