![]() |
|
#1
|
|||
|
|||
modulus arithmeticI have a quick question about using modulus arithmetic in calculations involving float variables. What data type should I use? I am trying to perform the following calculation, but I am getting a illegal error. Any sugge
stions would be appreciated. code: CPP / C++ / C Code:
CODE.cpp(42) : error C2296: '%' : illegal, left operand has type 'float' Error executing cl.exe. Thanks, ewallo Last edited by dsmith : 22-Feb-2004 at 21:58.
Reason: Added C syntax highlighting.
|
|
#2
|
||||
|
||||
|
Hi Ewallo. One quick thing, when you post c/c++ code if you start it with [c] and end it with [/c] it will highlight your code and make it much more readable
![]() C/C++ makes some assumptions about your results unless you use typecasting, so when you perform: CPP / C++ / C Code:
C defaults to give you a floating result. In order to perform integer division, you need to typecast your result as so: CPP / C++ / C Code:
Try something more like this CPP / C++ / C Code:
Also, WaltP has justed posted an excellent thread here wherein he talks a bit about parenthesis. If you get a chance it helps for *human* readability. Good luck |
|
#3
|
|||
|
|||
|
Quote:
dsmith, Thanks for the reply. I will give it a try. I will also make sure to mark my code correctly next time. Thanks again!! |
|
#4
|
||||
|
||||
|
Quote:
fmod(13.0, 2.25) is 1.75 fmod(13.0, 2.50) is 0.5 |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The