1. ## if statements?

whats up everyone,
It's your friendly neighborhood chap in again for some crazy tales of danger...well not really...just another question to make you roll your eyes in disgust, haha. So in this book I'm reading there's an example of an if statement that says:
Code:
```if (x%7 == 0 && y%7==0)
cout << "There's a mushroom here.\n";```
and then a few lines later in the book the author says that the following code would have the exact same effect:

Code:
```if ( !(x%7)  &&  !(y%7) )
cout << "There's a mushroom here.\n";```

Now I thought I had a firm grasp on many concepts...but I'm not understanding how the 2 if statements mean the same thing...any insight into this? Chap =

2. if x%7 == 0 wouldn't !(x%7) mean not 0 as well thus being making the 2 statements exact opposites of each other? Just my thinking...

3. ! basically flips a value.

For example:

!0 == 1

!1 == 0

!500 == 0

any nonzero value that is not'ed is zero, and zero not'ed is always non-zero (I believe it should always be 1, technically).

So, if you do:

!(5%7)

and 5%7 is 2, then you have

!(2)

which is 0, or false

also the same as if 2==0

which it doesn't. false.

*points and laughs at Hunter2 and stovellp*
vvvvvvvvvvvvvvvvvvvvvvvv

4. Anything other than 0 is interpreted as true, and 0 is interpreted as false. Therefore:
If x % 7 != 0 then:
x % 7 == 'true'

If x % 7 == 0 then:
x % 7 == 'false'

Logically then, where x % 7 == 0, x % 7 is 'false', so !(x % 7) is true.

**EDIT**
Beaten

5. x%7 == 0 divides x by seven and gives a remainder of 0.
0 == 0 is true, so the statement is executed.

!(x%7) also divides x by seven, and and gives a remainder of 0.
!0 is the same as 0 == 0, and this the statement is again executed.

Put it in your compiler and you'll see what I mean.

I hate using "!()", because it confuses people for exactly this reason. Replace "!(..)" with "== 0" everywhere you see it, and it'll make much more sense.

Edit: ahh you both beat me.

6. haha I completely overlooked that minor obvious detail and realized why that statement meant the same...I was about to write a post saying so and then you 2 came along and made me look bad...damn you! haha thanks for the insight though...any extra words of wisdom are always appreciated...the drinks are on me tonight!!

***
Edit: ahem...you THREE came along grrr

7. Originally Posted by Chaplin27
the drinks are on me tonight
I'm going to hold you to that. >.<

8. Originally Posted by jverkoey
I'm going to hold you to that. >.<
haha...damn, you ever make an offer so you look like the nice guy and then someone actually goes against the unwritten law of never accepting such offers and actually takes you up on it? Well ummm...good...me either...sigh...