/******************************************************************************
Problem: Write a program that converts a binary number to decimal
notation.
Include a loop that lets the user repeat this computation for
new
input values again and again until the user says he or she wants
to end the program.
Course: C++
Tutor : Guillermo Julca
Mercy College
View Output
*******************************************************************************/
//---------------------------------------------------------------------------
#pragma hdrstop
#include <iostream.h>
#include <conio.h>
#include <math.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
long int binary;
int i;
int decimal;
int dig;
char ans;
do
{
cout<<"Enter a binary number : ";
cin>> binary;
decimal = 0;
i= 0;
do
{
dig = binary % 10;
decimal = decimal + dig * pow(2,i);
binary = binary / 10;
i++;
} while( binary != 0);
cout<<"The number in decimal base is : " <<
decimal<<endl;
cout<<"Continue (Y/N) ? : " ;
cin>> ans;
}while(ans=='Y' || ans=='y');
getchar();
return 0;
}
View Output
//---------------------------------------------------------------------------