Home Forums C Programming plzz help me out ……….. Re: Re: plzz help me out ………..

#3636
GWILouisaxwzkla
Participant

Could do this:


/****************************************************************
* File Name : c:programstempCG.cpp
* Date : February 21 , 2010
* Comments : new project
* Compiler/Assembler : Visual C++ 6.0
* Modifications :
*
*
*
*
*
* Program Shell Generated At: 1:00:53 a.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


#include < iostream >
//#include < string.h >
//#include < conio.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >

using namespace std;

//main function ******************************

int main ( )
{

char ch;
int i;
char newline = 10;
float decimalEquivalent = 0;
float multiplier = .5;

cout << "enter a binary fraction: " ;

ch = cin.get(); //get decimal point
ch = cin.get() ; //get first digit of number

while ( ch != newline ) //while not at the end of input
{
decimalEquivalent = decimalEquivalent + ( ch - '0' ) * multiplier;
multiplier = multiplier * .5;
ch = cin.get() ; // get next digit
}

cout << endl << endl;
cout << "decimal equivalent is : " << decimalEquivalent << endl;
}