I can get any number to work as long as it doesnt include a 0. If it has a 0 the reversed number just comes out with the 0 on the end. I cannot figure out why. I think may have just made it too complicated and need to redo it. But if someone can help me I would appreciate it
[CODE=cpp]
int reverseDigit(in t a)
//reverseDigit reverses the order of the digits in an integer. So 1234 becomes 4321
//It only has to be passed the integer, and it returns its reversed order
{
int x = 1; //for while loop
if(a < 10) return a;
else
{
int b = (a%10)*10;
cout << b << endl;
int c = reverseDigit(a/10);
if(b==0) return (c*10);
else if(c < 10) return (c+b);//if c is less than 10 it only needs to be added to b
else //else we have to find how big b has to be for the next decimal point past c
{
while(x <= c) x = x*10;
b = x*(a%10);
return (b+c);
}
}
}
[/CODE]
[CODE=cpp]
int reverseDigit(in t a)
//reverseDigit reverses the order of the digits in an integer. So 1234 becomes 4321
//It only has to be passed the integer, and it returns its reversed order
{
int x = 1; //for while loop
if(a < 10) return a;
else
{
int b = (a%10)*10;
cout << b << endl;
int c = reverseDigit(a/10);
if(b==0) return (c*10);
else if(c < 10) return (c+b);//if c is less than 10 it only needs to be added to b
else //else we have to find how big b has to be for the next decimal point past c
{
while(x <= c) x = x*10;
b = x*(a%10);
return (b+c);
}
}
}
[/CODE]
Comment