I am using c++ and need to devise a method to determine the check digit of a credit card. The user enters the card no. as a string. The card no is then divided into blocks of length, x. these blocks are then added.
I have the code to convert the string into and integer, however i am stuck at how to divide the string into consecutive blocks. Logically, i think i must first divide the string into these blocks then convert those smaller strings into integers.
Here is the code to convert to integer. any idea to to divide the string say into blocks of 4 characters?
thanks in advance
int convert(string str)
{
int m;
int i= 0;
int intValue=0;
int strLength = str.length()-1;
while(i<=strLength){
m=str.at(i);
intValue=intValue*10+(m-'0');
i++;}
return intValue;
}