Ok so I manage to built the program I want but there are problems. #1 The conversion from octal to decimal is not correct. #2 The conversion from hexadecimal to decimal some answers are correct. #3 I don't know how to character array this program. So what I am asking is to help me correct my #1 & 2 problems and my #3 problem help me how to put this in character array. My defense is tomorrow and I'm really dead if I can't put this program in to correct that what my professor is asking. Here's the source code note this is in Turbo C++.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char value;
char t, u, v;
char answer;
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=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<<"Decimal equivalent is: "<<sum7<<endl;
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 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;
}