# c++ Convert decimal into other bases

 madhankumar 27-05-2013, 07:01 AM Hello, I am learning and creating a C++ code that converts decimal into other bases. Here is a code I found in internet search just the basic entering of numbers and validation, but it is not working for me. Code: `int getbases (int base, int choice); int convert (int base, int choice, int newbase); int main() {     int base, choice, newbase;          getbases ( base, choice);     convert (base, choice, newbase);          system ("pause");     return 0; } int getbases (int base, int choice)     {     cout <<" Please Enter a base of 2, 4, or 8 please." << endl;     cin >> choice;                 //Checking base input 2,4,8         while(((choice < 2) || (choice > 2)) && ((choice < 4) || (choice > 4))                    && ((choice < 8 || choice > 8)))          {             cout <<" Please Enter a base of ONLY 2, 4, or 8 please." << endl;             cin >> choice; // closing while             }                      cout << " Please Enter any decimal number:" << endl;     cin >> base;          while (base <= 0)           {              cout <<"Please enter a decimal greater then Zero" << endl;              cin >> base;               } // closing while                 return base, choice;       } int convert (int base, int choice, int newbase) {      }` Suvarna 29-05-2013, 10:16 PM I am providing a simple program that uses a switch statement for converting a decimal number to base 2 - binary, base 8 - octal and base 16 - hexadecimal numbers. Code: `#include #include void main() { int a,n,i=0,k,ch,rem,j,q,temp,bi,o,h; char b; clrscr(); cout<<"Enter a decimal number\n"; cin>>n; for(k=0;k<3;k++) { cout<<("\n Enter the choice u want to do:\n 1. Decimal to Binary\n 2. Decimal to octal\n 3. Decimal to Hexadecimal\n"); cin>>ch; switch(ch) { case 1:     bi=n;     while(bi!=0)     {         a[i++]=bi%2;         bi=bi/2;     }     cout<<"\nBinary number is :";     for(j=i-1;j>=0;j--)     {         cout<=0;j--)     {         cout<=0;j--)     {         cout<