I am trying to have a program take numbers from any base and convert them to any other base. So far I can take a decimal to 8 and 16, yet I can't finalize the program to get it to do binary and say 2.
Thanks for any help.




#include <stdio.h>
#include <iostream.h>
void to_binary(int i);

int main()

{


int i;



{
cout << "Enter a number:" << endl;
cin >> i ;
dec(cout); // Set output to decimal
cout << '\\' << i << '\\' << " = " << i;
oct(cout); // Set output to octal
cout << " = 0" << i;
hex(cout); // Set output to hex
cout << " = 0x" << i << '\n';
to_binary(i);
//bin(cout); // Set output to binary
//cout << " = 0" << i << '\n';

}
return 0;
}


void to_binary(int n) //recursive function
{
int r;
r = n % 2;

if (n >= 2)
to_binary(n / 2);
putchar('0' + r);
return;
}