I’m trying to write a program that checks 15-16 digit inputs and see what bank they belong to. I’m not familiar with the language I’m coding in(c++), and would like some pointers. I know you can’t copy and paste without the rest of the code, but it would be to long to post all of it. I just need a little adivce on a couple things.
Right now I have the program checking the length of the input and what the first two values of the string are. I would like to know if there is an easier way then what I have right now.
if(cLen==15 && c[0]== 3 && c[1]==4)
and
if(cLen==15 && c[0]== 3 && c[1]==7)
cause all I need is to find Strings that have the first two nums to be 34 or 37
secondly I need to check if the string has first values of 51 through 55
and lastly I need to check if the string contains 6011 at the beginning.
string validatebankcc(string c, int cLen, bool& ccOK) {
string bankcc;
if(cLen==15 && c[0]== 3 && c[1]==4)
bankcc = "AmericanExpress";
if(cLen==15 && c[0]== 3 && c[1]==7)
bankcc = "AmericanExpress";
if(cLen==16 && "6011 in beginning")
bankcc = "Discover";
if(cLen==16 && c[0]==5 && c[1]==1)
bankcc="MasterCard";
if(cLen==16 && c[0]==5 && c[1]==5)
bankcc="MasterCard";
if(c[0]==4)
bankcc="Visa";
else
bankcc = "Uknown Bank"
return bankcc;
Though overall design is bad. Returning bank name as string is crying for trouble (which also leads to useless ccOK flag, which can be replaced by BANK_UNKNOWN or smth like that. Passing string length along with string which known about it length also smells like trouble.