WEBVTT

00:00.530 --> 00:06.550
He went over some boolean logic rules last time but we haven't learned what it means in C++ yet.

00:06.980 --> 00:11.970
So to create a million variable we write them like this.

00:11.970 --> 00:15.350
So we say pool just short for Boullion.

00:15.350 --> 00:21.910
That's the type in which you give it the identifiers of hooly in my boolean

00:27.430 --> 00:35.530
in course who's only have two values and they are of course true.

00:36.900 --> 00:49.370
Or False and True or false are also keywords in C++ say true or false both keywords.

00:51.490 --> 00:56.730
So there are also other operators that can evaluate to TRUE and FALSE.

00:56.920 --> 01:08.930
The greater than sign less than sign and e greater than or equal to sign and the less than or equal

01:09.110 --> 01:15.460
sign all of these will produce a true or false value.

01:15.460 --> 01:17.520
So let's look an example.

01:17.540 --> 01:24.060
Samian bhool results in 10 is greater than 3.

01:24.220 --> 01:26.650
So this of course this is true.

01:26.680 --> 01:27.330
Right.

01:27.700 --> 01:34.680
So you can even put this out alue So it's

01:38.010 --> 01:41.250
as it's.

01:41.380 --> 01:41.740
It's

01:49.850 --> 01:52.160
an see what happens.

01:52.960 --> 01:55.750
So your result is 1.

01:55.780 --> 01:57.270
So why is that.

01:57.310 --> 02:10.690
Well booleans internally are represented by numbers so true here is represented by 1 and FALSE is represented

02:10.750 --> 02:14.010
by 0.

02:14.070 --> 02:17.990
In fact True's not actually are by one but that's the output.

02:17.990 --> 02:21.680
It'll have to is really anything.

02:24.090 --> 02:37.600
Except zero actually any number the size 0 is considered true in terms of boolean logic.

02:37.680 --> 02:47.080
So there's also another operator that can evaluate to TRUE and FALSE which is the quality.

02:47.080 --> 02:55.020
Operator So which is defined as two equal signs.

02:55.110 --> 03:05.790
A lot of students will get this confused with the assignment operator as they both use equal signs and

03:05.790 --> 03:14.980
just remember that if you're testing for equality you always want to use two equal science one equal

03:14.980 --> 03:18.430
sign means assignment.

03:18.490 --> 03:24.410
This means compare two or equals two.

03:25.230 --> 03:29.240
Lot of students will get this mixed up and I certainly did.

03:29.350 --> 03:33.230
I started at so.

03:33.230 --> 03:41.710
Also keep in mind as well that it's comparing to floating point numbers.

03:42.530 --> 03:45.990
It's with the equality sign is usually a bad idea.

03:46.000 --> 03:48.940
And let's see why that is.

03:49.540 --> 03:59.170
So safe float pie and fruit pie to say because it has two more values to it.

04:01.010 --> 04:07.810
So let's compare PI with PI to and see what the result.

04:07.840 --> 04:11.380
It's it's two.

04:11.530 --> 04:12.730
It's this

04:20.130 --> 04:21.130
in.

04:21.230 --> 04:22.160
So there you go.

04:22.160 --> 04:33.020
So their results is zero or false because the precision of pi 2 is not the same as the precision of

04:33.530 --> 04:36.250
the first pi.

04:36.260 --> 04:41.260
So if I said PI twos you put 1 4 and are in it again.

04:41.540 --> 04:51.060
This is true but usually you'll see that floating point numbers are basically never the same.

04:51.150 --> 04:59.520
You never really want to compare them as quality Neverland duty quality operation on two floats because

05:00.060 --> 05:02.570
typically this will never be true.

05:03.470 --> 05:08.950
But we will see later on how we can possibly fix this.

05:09.050 --> 05:20.610
But for now just know that just don't compare to floating point numbers with a quality.

05:20.640 --> 05:24.740
The other operator we can use.

05:24.740 --> 05:29.910
Here is the inverse operator.

05:30.050 --> 05:31.900
So let's say we had results.

05:32.060 --> 05:41.610
Is Well it's actually called the not operator which is exclamation point to result.

05:41.610 --> 05:44.580
So before we said this is false.

05:44.600 --> 05:47.040
So these are not the same right.

05:47.610 --> 05:55.200
But if we say result equals two not the result then it'll change whatever the value.

05:55.200 --> 05:59.310
So let's try it again and we see

06:05.840 --> 06:16.670
and we see that the result is 1 because it's switch or negated the false into a true.

06:16.870 --> 06:19.100
So the opposite of false is true.

06:24.250 --> 06:36.320
So there was actually another version of equality that we can use and it has to do with the not operator

06:36.420 --> 06:41.110
in say not equal to this.

06:41.270 --> 06:47.110
This says not equal to pi is not equal to pi 2.

06:47.440 --> 06:48.960
So this should be true.

06:51.710 --> 06:52.170
OK.

06:52.220 --> 06:54.140
See.

06:54.220 --> 06:59.460
So it's kind of like the opposite of the equal to.

06:59.510 --> 07:04.530
Another way you can write this is say equal to here and then say not here.

07:04.630 --> 07:05.620
This is equivalent

07:08.740 --> 07:09.190
staff.

07:09.340 --> 07:09.850
Yeah.

07:12.830 --> 07:23.840
So the last two operators are what we covered last time which are the and logical and logical or.

07:23.840 --> 07:26.170
So let's get rid of this

07:29.810 --> 07:39.870
just right this one and let's say we had true.

07:40.100 --> 07:49.280
And so we have to ampersands to make the logical answer remember that logical and is always to ampersands

07:50.370 --> 07:54.640
and false is of course should be false.

07:54.640 --> 07:55.040
Right.

07:55.120 --> 07:56.500
So you're in this

08:01.880 --> 08:06.020
you're in this it's false.

08:06.160 --> 08:20.770
Ceara we want to do or say it or true or church two vertical bars.

08:20.910 --> 08:29.670
So we have to ampersands four and in two vertical bars four or so.

08:29.670 --> 08:33.710
True or false of course is true.

08:34.660 --> 08:36.590
We want to make this false.

08:36.590 --> 08:48.060
You say true or false or false horses false for some reason it never once printed out properly.

08:48.400 --> 08:51.530
So the value of result is false.

08:53.210 --> 08:59.300
So let's do a few examples and really try to solidify this a bit.

08:59.420 --> 09:00.830
Let's use

09:05.300 --> 09:24.120
that and say we hand who a equals true in Rule B is false in it's have some integers in each x 10 y

09:24.510 --> 09:28.990
z or and you will have results.

09:29.110 --> 09:35.200
Lool so it's is.

09:35.330 --> 09:46.190
So it's a and b or x is greater than Y.

09:46.220 --> 09:53.310
So what is the output of this do you think so.

09:53.800 --> 10:00.870
A is true and B which is false will be false.

10:01.000 --> 10:05.040
Cause for and both would have to be true.

10:05.040 --> 10:13.520
For this to evaluate to true or X which is 10 y is zero.

10:14.860 --> 10:17.580
So 10 of course is greater than zero.

10:18.010 --> 10:22.780
So false or true is true.

10:24.510 --> 10:27.870
See it right and we are.

10:27.870 --> 10:30.180
So all your result is true.

10:30.560 --> 10:34.380
One do another example

10:39.170 --> 10:40.210
soon.

10:40.410 --> 10:41.970
A not A

10:44.760 --> 10:48.050
or B and.

10:49.280 --> 10:56.370
X X X X less than or equal to y

10:59.100 --> 11:00.290
k.

11:00.420 --> 11:02.870
What would be the output here.

11:03.270 --> 11:05.160
Well a is true.

11:05.190 --> 11:21.430
So not a is false or false is totally false and X is 10 so x is not less than Y which is 0.

11:21.480 --> 11:25.400
So this would also be false and the whole thing should be false.

11:26.940 --> 11:32.280
So try and it's let's try one more

11:35.950 --> 11:46.550
let's say not and those are using parentheses for these parentheses really do come in handy in especially

11:46.550 --> 11:47.410
in boolean logic.

11:47.420 --> 11:52.000
But any kind of earth Medich operation so let's say

11:54.630 --> 11:57.630
next mission.

11:58.090 --> 12:02.160
Actually equal.

12:04.140 --> 12:04.890
Equal

12:07.980 --> 12:09.540
today.

12:09.640 --> 12:13.370
So what would be the results of this well.

12:14.430 --> 12:22.530
True is definitely not equal to false and X is definitely not equal to whine because X is 10 and Y's

12:22.550 --> 12:23.530
0.

12:23.880 --> 12:29.430
So the whole thing should be false but it should be negated at the end.

12:29.430 --> 12:32.410
Right and that's why we have these parentheses.

12:32.880 --> 12:34.850
And the whole thing should be true.

12:37.190 --> 12:38.050
And it is

12:41.800 --> 12:49.240
so in the next lecture we'll be using this to actually start making our decisions in our output is.
