its not that I dont get how to use it but i'm just wondering why is it that for example if I had abc as a variable that

Code:

if (abc==!4)

wont work(well it does but if I entered in anything it assumes its false and goes onto the else statement)? since ! takes precedence shouldnt it be read
not 4 > == > abc and when reconstructed isnt it saying that if abc is equal to not 4 then?
I tried

Code:

if (!(abc==4))

and it worked but isnt it sortve the same as the if statement before just reworded to if its not equal to 4?

03-29-2004

Hammer

!4 equates to 0.
so the first test is abc == 0

the second test is completely different.
First abc == 4
then "not" the result.

03-29-2004

LegendsEnd

oh, how does !4 equate to 0 though, i still dont really get it
Now I have another problem with the loops, is FOR the same as WHILE except you can do more things variable wise with FOR? It seems pretty much the same and I tried adding a loop to:

before cout so it can ask the question again but the question just keeps getting asked and loops over and over, is there a way to make it not do that or would I have to create another variable and add a AND statement to the while code?

03-29-2004

alphaoide

I don't know if the following is your confusion (just wondering),
if not then nevermind...

A logical NOT !X is different from a bitwise NOT ~X. This: ~4 does not evaluate to zero.

03-31-2004

major_small

here's another way to think about it... when you just put if(constant), it kinda acts like this: if(constant==constant) which it always will, in your case, it would be if(4==4), and in your implementation if(!a), it would be similar to if(!a==a), which it doesn't...

03-31-2004

elad

!4

I like DougDbug's answer. AFAIK, all conditional statements need to be phrased in a true/not-true dichotomy. In C++ zero equates to false (not-true), and any non-zero values equate to true. Therefore if you say:

if(4)

then 4 is non-zero so it is interpretted by the compiler as saying if(true). If you say:

if(!4)

then the compiler probably first converts the statement to this:

if(!true)

and then to this:

if(false)

which is the same as this

if(0)

so in the end !4 == 0 when used as a conditional. Logically !4 could mean the value could be anything but 4 like -100 or 0 or 3, but when used as a conditional, !4 means 0, given the need for results that equate to either true or not-true.

03-31-2004

LegendsEnd

I still cant get the loop working but I understand the !4 thing equating to 0 now, thanks, and btw the program is supposed to be a joke type thing where 2+2 equals anything except 4 :P