Can anyone give me some help coz i need to make a program that
accepts inputted decimal number and converts it to Binary, Hexadecimal, Octal.
I should use looping statement, it should be function oriented, and uses switch case.

This will be the sample output:

====================================================
Input decimal number : 314

Choose type of conversion:
[1] Binary
[2] Hexadecimal
[3] Octal
[4] Exit

Enter your choice : 2

Hexadecimal equivalent : 1E

Try Again? [Y/N]
===================================================

Any help is greatly appreciated :sweat:

You will only get help if we see some actual effort. Get coding.

Ok, I got the formula for binary :

//Binary formula
int binary(int d)
{
for(i=0;d!=0;i++)
{
ck=d%2;
d=d/2;
}
printf("Binary Conversion is");
for(c=i-1;c>=0;c--)
{
printf("%d\n",ck[c]);
}
return(0);
}


I still can't get how to make it hexa,octal and how to make it in switch case and function

Did you miss the information about CODE tags? If so, just read the background on the box you typed your message in.

If binary is 2, hex is 16, and octal is 8, what do you think you need to change in the code you posted?

I have managed to code but I still encounter errors!

Here is my code

#include"stdio.h"
#include"conio.h"
int x,i,a,dec,con,c;
char o,Y;
int binbin(int d);
int hexhex(int d);
int octoct(int d);
void main(void)
{
clrscr();
printf("===============================================================================");
printf("\n**********************|D|E|C|I|M|A|L*******C|O|N|V|E|R|T|E|R*******************");
printf("\n===============================================================================");
gotoxy (30,5);
printf("Enter decimal number: ");
scanf("%d",&dec);
gotoxy(35,9);
printf("[1] Binary");
gotoxy(35,10);
printf("[2] Hexadecimal");
gotoxy(35,11);
printf("[3] Octal");
gotoxy(35,12);
printf("[4] Exit");
gotoxy(28,7);
printf("Choose type of conversion: ");
scanf("%d",&con);
switch(con){
case 1 :

{
printf("The binary equivalent is: %d",binbin(dec));
printf("\n Try again? [Y/N]");
scanf("%c",&o);
}
while(o==Y);
break;
case 2 :
do
{
printf("The Hexadecimal equivalent is: %d",hexhex(dec));
printf("\n Try again? [Y/N]");
scanf("%c",&o);
getch();

}
while(o==Y);
break;
case 3 :
clrscr();
do
{
printf("The octal equivalent is: %d",octoct(dec));
printf("\n Try again? [Y/N]");
scanf("%c",&o);
clrscr();
}
while(o==Y);
break;
case 4 :
clrscr();
break;
default:
clrscr();
printf("Invalid choice!");
break;
}
getch();
}

int z[77];
int binbin(int a)
{
for(i=0;a!=0;i++)
{
z[i]=a%2;
a=a/2;
}
for(c=i-1;c>=0;c--)
{
}
return(z[c]);
}
int octoct(int d)
{
for(i=0;a!=0;i++)
{
z[i]=a%8;
a=a/8;
}
for(i=i-1;i>=0;i--)
{
}
return(z[i]);
}
int hexhex(int d)
{
for(i=0;a!=0;i++)
{
z[i]=a%16;
a=a/16;
}
for(i=i-1;i>=0;i--)
{
if(z[i]==10)
x ='A';
else if(z[i]==11)
x ='B';
else if(z[i]==12)
x ='C';
else if(z[i]==13)
x ='D';
else if(z[i]==14)
x ='E';
else if(z[i]==15)
x ='F';
else
return(z[i]);
}

Welcome aboard..hope you'll enjoy it here. Your formatting is horrible...please look at the two anouncements at the top of the page, so you can place your code in tags. Also, in the future, before posting, search the forums to see if someone else had the same problem/assignment. We are willing to help, but we don't want to waste time doing the same thing over and over again...here are a few links that may be able to help you:
http://www.daniweb.com/forums/thread54706.html
http://www.daniweb.com/code/snippet655.html
http://www.daniweb.com/code/snippet656.html
Look around for the others....

And please learn to format your code! It's impossible to follow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.