Credit card validation

Hi I am very new to c++ programming and I was wondering if anyone could help me with a task I have been given. I have been given the template for a credit card validation program and I am unsure as to what I need to put into the bool function of the program. Any help is much appreciated.


#include<iostream>
#include<string>
#include<fstream>
#include<cmath>


using namespace std;


int convertChartoInt(const char digit)
{
int numericalDigit = digit - '0';

if (numericalDigit < 0 || numericalDigit > 9){
throw(0);
}
return(numericalDigit);
}


bool validateCardNumer(const string number) {
int reverseNumer[15];
bool cardStatus = false;
int evenCount = 0, oddCount = 0, calculatedCheckDigit = 0,
checkDigit=0;









}



int main()
{

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

int numberOfCards = sizeof(testCard) / sizeof(testCard[0]);

for (int i = 0; i < 10; 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;
}
review your requirements.
you need to perform the tests, and return whether the number is valid or not.

something like this
bool validateCardNumer(const string number input) //number be a terribad name for a string.
{
int reverseNumer[15]; //what is this? Looks useless.
bool cardStatus = true; //changed for simplicity of logic it was wrong
int evenCount = 0, oddCount = 0, calculatedCheckDigit = 0, //don't need to count both evens/odds the other is input.size - the one you know.
checkDigit=0;
for (const char& c : input)
{
oddcount += c&1;
checkDigit = somethingdigitish;
... do all the counting checking and whatnot
}
...
cardStatus &= (oddcout > something); //if it fails some condition make it false..
... etc
return cardStatus; //the final result of your tests.
}







Last edited on
Thanks for your help but those aspects that you have crossed out are apart of the template that I have been given. The parts that you have stated after the dots are the parts that I'm unsure on how to do.
Last edited on
post the full text. did they not tell you what the tests for the assignment ARE?
they will all look similar to the example I gave above .. loop, do something, evaluate if it is true or false, combine that in your final result.
the crossed out excess variables can be left in, but they are just unused variables most likely. you can use the name number, but it is poorly named.
Topic archived. No new replies allowed.