Number conversion

//this program is to convert the given numbers to decimal and binary.
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int dec,d,i,t,ch;
long int bin;
        cout<<"\n this program is made by mysticforce;
do
{
dec=bin=d=i=0;
cout<<"\n Menu \n";
cout<<"\n 1.Decimal to Binary";
cout<<"\n 2.Binary to decimal";
cout<<"\n 3.Exit";
cout<<"\n Choose your choice from the above options:  ";
cin>>ch;
switch (ch)
{
case 1:
cout<<"\n Decimal to binary";
cout<<"\n Enter a decimal number:  ";
cin>>dec;
t=dec;
while(dec!=0)
{
d=dec%2;
bin+=d*pow(10,i);
dec/=2;
i++;
}
cout<<t<<"\n in dec"<<bin<<"\n in bin";
break;
case 2:
cout<<"\n Binary to decimal ";
cout<<"\n Enter a binary number: ";
cin>>bin;
t=bin;
while(bin!=0)
{
d=bin%10;
dec+=d*pow(2,i);
bin/=10;
i++;
}
cout<<"\n the decimal number is"<<dec;
break;
case 3:
break;
default:
cout<<"errorable choice...............................";
break;
}

}while(ch!=3);
return 0;
}

Comments

Popular Posts