Credit Card Validation

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);
}


bool validateCardNumer(const string cardNumer){
int oddCount = 0, evenCount = 0,
calculatedCheckDigit = -1, // Why -1 ?
checkDigit;
int reversedNumbers[15];

bool cardStatus = false;


try {
checkDigit = convertChartoInt(cardNumer.at(15));

for (int i = 0; i < 15; i++)
{
reverseNumer[14 - i] = convertChartoInt(number.at(i));
}


for (int i = 0; i < 15; i = i + 2)
{

}



for (int i = 1; i <15; i = i + 2)
{

}

calculatedCheckDigit = (evenCount + oddCount) % 10;

cardStatus = (calculatedCheckDigit == checkDigit);
}
catch (...) {
cardStatus = false;
}
return(cardStatus);
}


int main(void) {
const string testCard[] = { "4686006570307405",
"4686006570307407",
"4093650457937474",
"4340423439668810",
"1234567812345670",
"5509415774265347",
"X234567812345670",
"4539281167952835",
"4532528637398511",
"4653549906803760" };

for (unsigned int i = 0; i <sizeof(testCard) / sizeof(testCard[0]); i++)
{
if (validateCardNumer(testCard[i]))
{
cout << " Card : " << testCard[i].c_str() << " is valid" << endl;
}
else {
cout << " Card : " << testCard[i].c_str() << " is Invalid" << endl;
}
}
return 0;
}
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.
Topic archived. No new replies allowed.