Tip:
Highlight text to annotate it
X
>> DAVID J. MALAN: So that last program had a bug whereby it reported that 0
is negative, even though technically 0 is neither positive nor negative.
But not a problem.
We can fix this bug by inserting another condition into our program.
>> Specifically, at line 12 I'm going to hit Enter.
And then add else if and equals equals 0, open curly
brace, close curly brace.
>> Now you'll notice that I said and typed equals equals as
opposed to just equals.
Now that's simply because C is already using a single equal sign as the
so-called assignment operator and in order to assign a value from the right
to a, say, variable on the left.
But in this case, we actually want to test n for equality with 0.
And to do that in C, you simply have to remember to use two equal signs.
>> Well, if n does indeed equal equal 0, I'm going to print out
the following instead.
Print F, you picked 0.
Save my file.
And now let's compile this as conditions 1.
>> Back at my blinking prompt, I'm going to run the program with dot slash,
conditions 1.
And let's do that same sanity check again as before.
1 for my int, which is indeed positive.
Let's rerun this as conditions 1 with a second input of, say, negative 1,
which is indeed negative.
>> Now let's test it with 0.
dot slash, conditions 1.
Enter.
0 and--
phew.
I indeed picked 0 this time.