Home › Forums › C Programming › plzz help me out ……….. › Re: Re: plzz help me out ………..
February 21, 2010 at 10:39 pm
#3636
Participant
Could do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <br /> /****************************************************************<br /> * File Name : c:programstempCG.cpp<br /> * Date : February 21 , 2010<br /> * Comments : new project<br /> * Compiler/Assembler : Visual C++ 6.0<br /> * Modifications :<br /> *<br /> *<br /> *<br /> *<br /> *<br /> * Program Shell Generated At: 1:00:53 a.m.<br /> =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /> <br /> <br /> #include < iostream ><br /> //#include < string.h ><br /> //#include < conio.h ><br /> //#include < math.h ><br /> //#include < iomanip ><br /> //#include < ctype.h ><br /> <br /> using namespace std;<br /> <br /> //main function ******************************<br /> <br /> int main ( )<br /> {<br /> <br /> char ch;<br /> int i;<br /> char newline = 10;<br /> float decimalEquivalent = 0;<br /> float multiplier = .5;<br /> <br /> cout << "enter a binary fraction: " ;<br /> <br /> ch = cin.get(); //get decimal point<br /> ch = cin.get() ; //get first digit of number<br /> <br /> while ( ch != newline ) //while not at the end of input<br /> {<br /> decimalEquivalent = decimalEquivalent + ( ch - '0' ) * multiplier;<br /> multiplier = multiplier * .5;<br /> ch = cin.get() ; // get next digit<br /> }<br /> <br /> cout << endl << endl;<br /> cout << "decimal equivalent is : " << decimalEquivalent << endl;<br /> }<br /> <br /> <br /> <br /> <br /> |