binary_calculator
please do give me feedback on
https://www.facebook.com/invigorating.arslaan
#include<iostream>
using namespace std;
void main()
{
int l,a,b=1,decimal=0;
int n;
bool bol=false;
cout<<"Add binary number ";
cin>>n;
while(n>0)
{
a=n%10;
if(a==1||a==0)
{
n=n/10;
a=a*b;
b=b*2;
decimal=decimal+a;
}
else
{
bol=true;
break;
}
}
if(bol==true||n<0)
cout<<"please enter binary number"<<endl;
else
cout<<"Decimal number is "<<decimal<<"."<<endl;
}
Comments
Post a Comment