im totally new at stack overflow, I usually just research stuff myself but I just started using xcode 4.2 and I cant help finding it weird.
These are the issues:
why cant i multiply by (1/2) but i can by 0.5? If i try the first option it will think its 0.
and second, is this if statement wrong?
if (-1 < x < 0)
I could swear i have done that in other programming languages but it wont work here, so i had to change to if ((-1 < x) && (x < 0))
Thank you for your time.
This is nothing to do with Xcode, it’s to do with the C language.
The first issue:
The C compiler treats
1and2as ints, and in integer math, 1 / 2 = 0. If you want to multiply as floats, you can do:or
In your second issue, the compiler will interpret
(-1 < x < 0)as((-1 < x) < 0), which is obviously not what you want, since(-1 < x)will return either 0 for false, or 1 for true. To do compound logic statements in C, you need to use&&for AND or||for OR: