I'm too beginner and things I say may not be correct. (+My English is terrible)
You need to do it twice, I mean the while loop.
Take a look at this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
using namespace std;
int main()
{
int a,b=0;
cin>>a;
while (a>0)
{
b=(b*10)+(a%10);
a=a/10;
}
cout<<b;
}
|
This code reverses a decimal number, for example:
123456789 will be 987654321 .
Your program is based on this algorithm, so it reverses your number, so you should do it twice:
FirstWay:First reverse number that user enters and then transfer it to the base he wants.
SecondWay:Do your while loop twice, but depends on the base the user wants, you need to calculate the modulo from that number.
In both ways you need to be careful about "ZERO"s, consider that a "0" is the last number of a number, so if you reverse it, it will be first and makes no sense.
(the FirstWay is better and more efficient.)
By the way I think there will be better ways, better ask a professional.