| | |
Void Functions
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
0
#11 30 Days Ago
Ah. Its a simple error on our hand.
We forgot that floats cannot be compared directly
0.33333 = 0.33 will not return true always and even it does, change in the execution environmet(compiler, hardware, etc) will behave unpredictably.
try :
and see if it works now....
Also read this: http://www.cygnus-software.com/paper...ringfloats.htm
Hope that solves the problem.
Cheers
We forgot that floats cannot be compared directly
0.33333 = 0.33 will not return true always and even it does, change in the execution environmet(compiler, hardware, etc) will behave unpredictably.
try :
C++ Syntax (Toggle Plain Text)
void diviGame(const double result, const double answer, int & diviWins, int & diviLosses, int & diviTotal) { if (fabs(answer - result) < 0.01 ) //decide winning diviWins++; else //or loss diviLosses++; diviTotal++; }
and see if it works now....
Also read this: http://www.cygnus-software.com/paper...ringfloats.htm
Hope that solves the problem.
Cheers
PEACE !
0
#14 29 Days Ago
Ah. Floats cant be compared directly. And even if you get a result, the same code might not work on different runtime environments(cmpiler, hardware, etc). Therefore u need to set a margin.
Improved code:
Hope this helps.
Cheers
Improved code:
C++ Syntax (Toggle Plain Text)
void diviGame(const double result, const double answer, int & diviWins, int & diviLosses, int & diviTotal) { if (fabs(answer - result) < 0.01 ) //decide winning diviWins++; else //or loss diviLosses++; diviTotal++; }
Hope this helps.
Cheers
PEACE !
![]() |
Similar Threads
- reStructure of code: include 2 void functions (C++)
- Void Functions (C++)
- void functions (C++)
- Error in void functions (C++)
- Making my void functions look at little better (C++)
Other Threads in the C++ Forum
- Previous Thread: Associating an icon with a custom file type
- Next Thread: Design problems, help!
| Thread Tools | Search this Thread |






