Can anyone edit this program from "Base 10 to any base" --->>> to "From any base to base 10 with character array" .I would really appreciate this a lot. I use turbo c++ compiler.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
void main(){
char value;
char t, u, v;
char answer;
do{
clrscr();
cout<<"**********NUMBER CONVERSION**********"<<endl;
cout<<endl;
cout<<"a - Binary"<<endl;
cout<<"b - Octal"<<endl;
cout<<"c - Decimal"<<endl;
cout<<"d - Hexadecimal"<<endl;
cout<<endl;
cout<<"Select a value to be converted: ";
cin>>value;
switch(value){
case 'a':
cout<<endl<<"[BINARY CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Octal"<<endl;
cout<<"b - Decimal"<<endl;
cout<<"c - Hexadecimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>t;
switch(t){
case 'a': //ok
cout<<endl<<"[BINARY TO OCTAL CONVERSION]"<<endl;
cout<<endl;
long b1,f1=1,d1=0,num5,result5[8]={0,0,0,0,0,0,0,0},flag5=0;
cout<<"Enter a Binary number: ";
cin>>b1;
cout<<"\n\n";
while(b1>0)
{
if((b1%10)==1)
{
d1=d1+f1;
}
b1=b1/10;
f1=f1*2;
}
num5=d1;
cout<<"Octal equivalent is: ";
for(int i5=0;i5<8;++i5)
{
result5[7-i5]=num5%8;
num5=num5/8;
if(num5==0)
break;
}
for(i5=0;i5<8;++i5)
{
if(result5[i5]!=0)
flag5=1;
if(flag5==1)
cout<<result5[i5];
}
cout<<endl;
break;
case 'b': //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;
case 'c': //ok
cout<<"[BINARY TO HEXADECIMAL CONVERSION]"<<endl;
cout<<endl;
long b3,f3=1,d3=0,r6[10],z6=0,number6;
cout<<"Enter a Binary number: ";
cin>>b3;
cout<<"\n\n";
while(b3>0)
{
if((b3%10)==1)
{
d3=d3+f3;
}
b3=b3/10;
f3=f3*2;
}
number6=d3;
while(number6>0)
{
r6[z6]=number6%16;
number6=number6/16;
z6++;
}
cout<<"Hexadecimal equivalent is: ";
for(int j6=z6-1;j6>=0;j6--)
{
if(r6[j6]==10)
cout<<"A";
else if(r6[j6]==11)
cout<<"B";
else if(r6[j6]==12)
cout<<"C";
else if(r6[j6]==13)
cout<<"D";
else if(r6[j6]==14)
cout<<"E";
else if(r6[j6]==15)
cout<<"F";
else
cout<<r6[j6];
}
cout<<endl;
break;
default:
cout<<endl;
}
break;
case 'b':
cout<<endl<<"[OCTAL CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Binary"<<endl;
cout<<"b - Decimal"<<endl;
cout<<"c - Hexadecimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>u;
switch(u){
case 'a': //ok
cout<<endl<<"[OCTAL TO BINARY CONVERSION]"<<endl;
cout<<endl;
long number4,dec7,rem7,i7=1,sum7=0;
cout<<"Enter an Octal number: ";
scanf("%o", &number4);
cout<<"\n\n";
dec7=printf("%d", number4);
while(dec7>0)
{
rem7=dec7%2;
sum7=sum7 + (i7*rem7);
dec7=dec7/2;
i7=i7*10;
}
cout<<"Binary equivalent is: "<<sum7<<endl;
break;
case 'b': //ok
cout<<endl<<"[OCTAL TO DECIMAL CONVERSION]"<<endl;
cout<<endl;
long number5;
cout<<"Enter an Octal number: ";
scanf("%o", &number5);
cout<<"\n\n";
printf("Decimal equivalent is: %d", number5);
break;
case 'c': //ok
cout<<endl<<"[OCTAL TO HEXADECIMAL CONVERSION]"<<endl;
cout<<endl;
long number6;
cout<<"Enter an Octal number: ";
scanf("%o", &number6);
cout<<"\n\n";
printf("Hexadecimal equivalent is: %X", number6);
break;
default:
cout<<endl;
}
break;
case 'c':
cout<<endl<<"[DECIMAL CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Binary"<<endl;
cout<<"b - Octal"<<endl;
cout<<"c - Hexadecimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>v;
switch(v){
case 'a': //ok
cout<<endl<<"[DECIMAL TO BINARY CONVERSION]"<<endl;
cout<<endl;
long dec1,rem1,i1=1,sum1=0;
cout<<"Enter a Decimal number: ";
cin>>dec1;
cout<<"\n\n";
while(dec1>0)
{
rem1=dec1%2;
sum1=sum1 + (i1*rem1);
dec1=dec1/2;
i1=i1*10;
}
cout<<"Binary equivalent is: "<<sum1<<endl;
break;
case 'b': //ok
cout<<endl<<"[DECIMAL TO OCTAL CONVERSION]"<<endl;
cout<<endl;
long num2,result[8]={0,0,0,0,0,0,0,0},flag2=0;
cout<<"Enter a Decimal number: ";
cin>>num2;
cout<<"\n\n";
cout<<"Octal equivalent is: ";
for(int i2=0;i2<8;++i2)
{
result[7-i2]=num2%8;
num2=num2/8;
if(num2==0)
break;
}
for(i2=0;i2<8;++i2)
{
if(result[i2]!=0)
flag2=1;
if(flag2==1)
cout<<result[i2];
}
cout<<endl;
break;
case 'c': //ok
cout<<endl<<"[DECIMAL TO HEXADECIMAL CONVERSION]"<<endl;
cout<<endl;
long r[10],z=0,number;
cout<<"Enter a Decimal number: ";
cin>>number;
cout<<"\n\n";
while(number>0)
{
r[z]=number%16;
number=number/16;
z++;
}
cout<<"Hexadecimal equivalent is: ";
for(int j=z-1;j>=0;j--)
{
if(r[j]==10)
cout<<"A";
else if(r[j]==11)
cout<<"B";
else if(r[j]==12)
cout<<"C";
else if(r[j]==13)
cout<<"D";
else if(r[j]==14)
cout<<"E";
else if(r[j]==15)
cout<<"F";
else
cout<<r[j];
}
cout<<endl;
break;
default:
cout<<endl;
}
break;
case 'd':
cout<<endl<<"[HEXADECIMAL CONVERSION]"<<endl;
cout<<endl;
cout<<"a - Binary"<<endl;
cout<<"b - Octal"<<endl;
cout<<"c - Decimal"<<endl;
cout<<endl;
cout<<"Convert to: ";
cin>>v;
switch(v){
case 'a': //ok
cout<<endl<<"[HEXADECIMAL TO BINARY CONVERSION]"<<endl;
cout<<endl;
long number1,dec8,rem8,i8=1,sum8=0;
cout<<"Enter an Hexadecimal number: ";
scanf("%X", &number1);
cout<<"\n\n";
dec8=printf("%d", number1);
while(dec8>0)
{
rem8=dec8%2;
sum8=sum8 + (i8*rem8);
dec8=dec8/2;
i8=i8*10;
}
cout<<"Binary equivalent is: "<<sum8<<endl;
break;
case 'b': //ok
cout<<endl<<"[HEXADECIMAL TO OCTAL CONVERSION]"<<endl;
cout<<endl;
long number2;
cout<<"Enter a Hexadecimal number: ";
scanf("%X", &number2);
cout<<"\n\n";
printf("Octal equivalent is: %o", number2);
break;
case 'c': //ok
cout<<endl<<"[HEXADECIMAL TO DECIMAL CONVERSION]"<<endl;
cout<<endl;
long number3;
cout<<"Enter a Hexadecimal number: ";
scanf("%X", &number3);
cout<<"\n\n";
printf("Decimal equivalent is: %d", number3);
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;
}