So I`m trying to write a code for program that turns any Natural dec number to a number with any Natural base. Basically the task is to make such program for Natural numbers to convert to numbers with base from 2 to 16, but I am trying to generalize it and then exclude what is in task... I have been messing with the code for quite a while now and I hink I have completly messed it up. I will be thankfull for any pointers for what is wrong or what can I do better or what exclude...
I will be helpfull for any help!
#include<iostream>
usingnamespace std;
void convertdectob(int m, int n)
{
if (m == 0)
return;
int x = m % n;
m /= n;
if (x < 0)
m += 1;
convertdectob(m, n);
cout<< x < 0 ? x + (n * -1) : x;
return;
}
int main()
{
int m,n;
cout<<"Enter the integer to convert(m): ";
cin>>m;
cout<<"Enter the base 2<=n<=16: ";
cin>>n;
if(n<2) cout<<"Not the right base"<<endl;
if(n>16) cout<<"Not the right base"<<endl;
if (m>0)
{
convertdectob(m, n);
}
else
cout<<"0"<<endl;
return 0;
}