hi, I have a problem with my program. what the program does is prints a number backwards. however, the function fails for certain numbers. why is this?
I am currently using MSVC++ 6.0
Code:
#ifndef _INC_IOSTREAM
#include <iostream.h>
#endif
long int newvalue = 0; //variable to store the number backwards
void PrintNumberBackwars(long int x) //recursive function
{
long int temp = x / 10;
temp = x - temp * 10;
newvalue = newvalue * 10 + temp;
cout << temp;
x /= 10;
if ( x != 0 ) PrintNumberBackwards(x);
else cout << endl;
}
int main(void) // main driver function
{
long int x;
cin >> x;
if ( cin.fail() ) return 0;
PrintNumberBackwards(x);
cout << newvalue;
return 0;
}