TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MICHAEL RATHBURN
from: CHRIS DOWNS
date: 1997-10-22 06:49:00
subject: Re: Help Please

 MR> Please if you have time please look at this code and tell me what is
 MR> going wrong all it is supposed to do is get the user to enter the
 MR> quoted char,int and float check they have input the correct data then
 MR> output the data but the float check cocks up please tell me why.
 FASCINATING!!
 First off, there were some problems with the logic of the program.
 You didn't use braces around some of the else deals so that program
 control didn't flow as I suppose you expected.  But that's not what
 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> }
 When I ran this thing, I would type in 3.142 and the program thinks that 
 pi is either less than 3.142 or greater than 3.142. 
 There are two ways to make it work right.  One is to declare pi to be a 
 double.  The other is to cast your numeric constants to floats.
 So the following will (consistently?) work
 if (pi  (float)3.142)
 {
    ...
 }
 I would love to hear a good explanation as to why 
 3.142(double) != 3.142(float)
 
-!-
 þ Blue Wave/QWK v2.12 þ
---
 þ Blue Wave/QWK v2.12 þ
---------------
* Origin: St. Louis Users Group (1:100/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.