stuck here. Luhn Formula. can't get code to work for first multiplying each individual odd term by 2 then summing them (also take 10 away if the multiplied value is > 9) then summing them wilh the even numbers. I have the bare bones here. Any help would be greatly appreciated only started coding.
#include "stdafx.h"
#include "iostream"
using namespace std;
class CreditCardValidation {
private:
static int convertChartoInt(const char digit);
public:
static bool validateCardNumer(const string cardNumer);
};
int convertChartoInt(const char digit)
{
int numericalDigit = digit - '0';
if (numericalDigit < 0 || numericalDigit > 9)
{
// Not a numerical digit, throw an exception
throw(0);
}
return(numericalDigit);
}
I've taken a look at your code and it's pretty confused.
My concerns are:
Why do you need a class at all? Not every program is object oriented. You've clearly realized that your code doesn't fit in a class, but you feel the need to have one anyway. Have you been coding in Java?
Why are you using char[]? Use string for strings. This program shouldn't use char arrays to hold the inputs.
Have you looked at the algorithm? I mean, have you worked thru the algorithm with pencil and paper? There is no reversing of the input and all that stuff. So why does it appear in your program?
I don't see the modulo 10 check against zero at the end, so clearly, you haven't implemented the whole algorithm.