OK so I'm almost done with my program. How to put this in function like putting each case like void Binary2Decimal() , void Octal2Decimal() & , void Hexa2Decimal() in "TURBO C++"? Call a function like I only want to display only the Binary to Decimal case.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
char value;
char t, u, v;
char answer;
void main()
{
do{
clrscr();
cout<<"Conversion from any base to base 10"<<endl;
cout<<endl;
cout<<"a - Binary"<<endl;
cout<<"b - Octal"<<endl;
cout<<"c - Hexadecimal"<<endl;
cout<<endl;
cout<<"Select a value to be converted: ";
cin>>value;
switch(value){
case 'a':
cout<<"[BINARY CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Decimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>t;
switch(t){
case 'a': //ok
cout<<endl<<"[BINARY TO DECIMAL CONVERSION]"<<endl;
cout<<endl;
long b2,f2=1,d2=0;
cout<<"Enter a Binary number: ";
cin>>b2;
cout<<"\n\n";
while(b2>0)
{
if((b2%10)==1)
{
d2=d2+f2;
}
b2=b2/10;
f2=f2*2;
}
cout<<"Decimal equivalent is: "<<d2<<endl;
break;
default:
cout<<endl;
}
break;
case 'b':
cout<<endl<<"[OCTAL CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Decimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>u;
switch(u){
case 'a': //ok
cout<<endl<<"[OCTAL TO DECIMAL CONVERSION]"<<endl;
cout<<endl;
long number4,dec7,rem7,i7,sum7;
cout<<"Enter an Octal number: ";
scanf("%o", &number4);
cout<<"\n\n";
dec7=printf("%d", number4);
{
rem7=dec7%8;
sum7=sum7 + (i7*rem7);
}
printf("Decimal equivalent is: %d", number4);
break;
default:
cout<<endl;
}
break;
case 'c':
cout<<endl<<"[HEXADECIMAL CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Decimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>v;
switch(v){
case 'a': //ok
cout<<endl<<"[HEXADECIMAL TO DECIMAL CONVERSION]"<<endl;
cout<<endl;
long number1,dec8,rem8,i8=1,sum8=0;
cout<<"Enter a Hexadecimal number: ";
scanf("%X", &number1);
cout<<"\n\n";
dec8=printf("%d", number1);
{
rem8=dec8%16;
sum8=sum8 + (i8*rem8);
}
printf("Decimal equivalent is: %d", number1);
break;
default:
cout<<endl;
}
break;
default:
cout<<endl;
}
cout<<endl;
cout<<"Do you want to continue NUMBER CONVERSION?(y/n) ";
cin>>answer;
}
while(answer == 'y');
cout<<endl;
}

Recommended Answers

All 5 Replies

Not indenting your code makes it very difficult to read... :-(

This is cross post of the same thread in c++ forum?

Cross posting like this causes more problems than it's worth

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.