1
00:00:00,000 --> 00:00:03,290
>> DAVID J. MALAN: So that last program had
a bug whereby it reported that 0

2
00:00:03,290 --> 00:00:07,220
is negative, even though technically
0 is neither positive nor negative.

3
00:00:07,220 --> 00:00:08,000
But not a problem.

4
00:00:08,000 --> 00:00:11,820
We can fix this bug by inserting another
condition into our program.

5
00:00:11,820 --> 00:00:14,500
>> Specifically, at line 12
I'm going to hit Enter.

6
00:00:14,500 --> 00:00:19,560
And then add else if and equals
equals 0, open curly

7
00:00:19,560 --> 00:00:21,900
brace, close curly brace.

8
00:00:21,900 --> 00:00:24,650
>> Now you'll notice that I said
and typed equals equals as

9
00:00:24,650 --> 00:00:26,050
opposed to just equals.

10
00:00:26,050 --> 00:00:29,880
Now that's simply because C is already
using a single equal sign as the

11
00:00:29,880 --> 00:00:33,630
so-called assignment operator and in
order to assign a value from the right

12
00:00:33,630 --> 00:00:35,950
to a, say, variable on the left.

13
00:00:35,950 --> 00:00:39,700
But in this case, we actually want
to test n for equality with 0.

14
00:00:39,700 --> 00:00:43,950
And to do that in C, you simply have
to remember to use two equal signs.

15
00:00:43,950 --> 00:00:47,340
>> Well, if n does indeed equal equal
0, I'm going to print out

16
00:00:47,340 --> 00:00:48,730
the following instead.

17
00:00:48,730 --> 00:00:53,690
Print F, you picked 0.

18
00:00:53,690 --> 00:00:54,700
Save my file.

19
00:00:54,700 --> 00:00:59,090
And now let's compile this
as conditions 1.

20
00:00:59,090 --> 00:01:02,670
>> Back at my blinking prompt, I'm going
to run the program with dot slash,

21
00:01:02,670 --> 00:01:04,180
conditions 1.

22
00:01:04,180 --> 00:01:06,970
And let's do that same sanity
check again as before.

23
00:01:06,970 --> 00:01:09,750
1 for my int, which is
indeed positive.

24
00:01:09,750 --> 00:01:14,480
Let's rerun this as conditions 1 with
a second input of, say, negative 1,

25
00:01:14,480 --> 00:01:16,180
which is indeed negative.

26
00:01:16,180 --> 00:01:18,060
>> Now let's test it with 0.

27
00:01:18,060 --> 00:01:19,575
dot slash, conditions 1.

28
00:01:19,575 --> 00:01:20,715
Enter.

29
00:01:20,715 --> 00:01:22,665
0 and--

30
00:01:22,665 --> 00:01:23,435
phew.

31
00:01:23,435 --> 00:01:25,670
I indeed picked 0 this time.

32
00:01:25,670 --> 00:01:27,330