Mar 26, 2016 at 10:31pm UTC
I know it doesn't work. But how do I fix it.
Mar 26, 2016 at 10:50pm UTC
If it's negative, make it positive, find the reverse, and then make that negative.
I'm assuming that you want, for example, -91 to be reversed to -19.
Mar 26, 2016 at 11:34pm UTC
I changed it to something that works with negative or positive, but doesn't work for overflow. It does not return 0 on overflow like it's supposed to because I used a long.
#include <iostream>
using namespace std;
class Operations
{
long c;
public:
void inputNumber()
{
cout << "Input a number\n";
cin >> c;
}
long reverseNumber()
{
long invert = 0;
while (c != 0)
{
invert = invert * 10;
invert = invert + c%10;
c = c/10;
}
return invert;
}
};
int main()
{
long result;
Operations t;
t.inputNumber();
result = t.reverseNumber();
cout << "Number obtained on reversal = " << result << endl;
return 0;
}