Hi came up with his code, basically to reverse whatever input you key in. However when i key in 0 or 0001 or -101 they donot reverse.What have i done wrong and how to correct?
Code:
#include <iostream>
using namespace std;
int main ()
{
long int y = 0,x;
cout <<"Enter any numeric value to be reversed:";
cin>> x;
while (x > 0)
{
y *= 10;
y += x % 10;
x /= 10;
}
cout <<y <<"\n";
return(0);
}