Hello.
I want to create a program that converts numbers between bases smaller than 10.
My problem is converting from base 10 to base smaller then 10 - the number comes out backwards.
For example, if you'll put the number 312 in base 4 and choose to convert to base 5 you'll get 402 instead of 204.
I know way this is happen but i have no idea how to do it other way.
Thanx.
void main()
{
int nUserNumber;
int nNumberBase;
int nDestBase;
int nDevNumber;
int nResultNumber =0 ;
int i = 0;
int r;
int nSecResult;
// Getting user number and base
cout << "Enter number:" << endl;
cin >> nUserNumber;
cout << "Enter the number of base:" << endl;
cin >> nNumberBase;
cout << " Enter number of base destination:" << endl;
cin >> nDestBase;
//Convert number from base under < 10 to base = 10
if ((nNumberBase != 10) && (nNumberBase != nDestBase))
{
// Convert from base < 10 to base = 10
while (nUserNumber !=0)
{
nDevNumber = nUserNumber % 10;
nUserNumber = nUserNumber / 10;
r = pow (nNumberBase, i);
nResultNumber += nDevNumber *r;
i ++;
}
// Convert from Base 10 to Base < 10
while (nResultNumber !=0 )
{
nSecResult = nResultNumber % nDestBase;
nResultNumber = nResultNumber /nDestBase;
cout << nSecResult; // My problem is right here!
// I need to save the number some how and then revers it or to do it in a different way.
}
}
system("pause");
}