>> C_PLUSPLUS <<
Thursday, October 23, 1997
Hello Chris!
Wednesday, October 22, 1997, Chris Downs writes to Michael Rathburn:
MR>> Please if you have time please look at this code and tell me what
MR>> is going wrong all it is supposed to do is get the user to enter
MR>> the quoted char,int and float check they have input the correct
MR>> data then output the data but the float check cocks up please
MR>> tell me why.
CD> FASCINATING!!
CD> First off, there were some problems with the logic of the program.
CD> You didn't use braces around some of the else deals so that program
CD> control didn't flow as I suppose you expected. But that's not what
CD> was so interesting.
MR>> float pi;
MR>> cout << "\n\tPlease enter pi ie:-3.142 ";
MR> cin >>> pi;
MR>> if(pi 3.142 )
MR>> {
MR>> cout << "\n\tWrong Formula";
MR>> continue;
MR>> }
CD> When I ran this thing, I would type in 3.142 and the program thinks
CD> that pi is either less than 3.142 or greater than 3.142.
That is correct, the program tests that pi = 3.142 is not good.
3.142 is NOT smaller than 3.142 and 3.142 is NOT greater than 3.142
use:
if(pi 3.142 )
-------
or
if(pi = 3.142 )
-----
Regards, Henk
E-mail: hdeutekom@bundy.idn.nl
--- FMail/386 1.02+ & GoldED/386 2.50+
---------------
* Origin: Henk's point, The Netherlands (2:283/6.22)
|