0:00 was gonna guys? This is Bucky. And welcome to your 26th C++ tutorial. 0:04 in this tutorial, I'm gonna be talking to guys about something called logical 0:07 operators. now let me go ahead and build a simple program right now. 0:11 say we're the owner of a nightclub and we wanted to calculate whether a person 0:16 was allowed in 0:16 or whether they weren't. so the first we looked at their age 0:20 and we're going to make sure it's you know over 21 0:23 because we gonna get sued. And next they thing were going to be looking at is how much 0:26 money they have because 0:28 we don't want to allow poor people into our, you know, 0:31 five-star nightclub, so let's say they need more than 0:34 five hundred dollars. so let's go ahead make this like person 0:38 has six hundred fifty dollars. so we can test this 0:41 like this if age is greater than 21. 0:45 and if money 0:49 is greater than what I say, 500? uhm, 0:53 whu what did I just hit? insert, where the heck is my insert key on this keyboard? 0:58 this keyboard is really messed up. now I look about it. 1:01 so took me like five minutes a find the answer. It is actually by my, uh, 1:06 up and down arrows. that's weird. so anyways, 1:09 now that we had our nice little break, we go ahead write something like cout 1:14 uhm, you are allowed 1:18 in and make sure you sell it within nine and you 1:21 and makes you so in I honor. or else this program just won't work. 1:25 so let's go ahead and run this. and see what we get. We are allowed in because 1:30 we indeed are greater than 21 and we have more than five hundred dollars 1:35 So, you are saying alright. pretty cool program. Maybe open up a night club now 1:39 but check this out, this can get kind of confusing after a while because 1:44 this brace goes to this and this goes to this. were pretty 1:48 easily distinguishable but what if we had five different tests that we need to 1:52 check what if we had twenty different tests? 1:54 well one little mistake say we had this over here 1:58 Our program is still going to run fine but looks like this goes to this 2:01 and this goes to main or something. who knows where this one goes. 2:05 I mean putting a bunch if statements inside other if statements 2:08 is not always the best idea. so we have a better way 2:12 to test two or more things. and thats through the use of something called logical operators. 2:17 and this allows you to make all your test on a single line. 2:20 so here's what we can do in this case. go ahead and make your if statement and then 2:25 my as well 2:26 make our cout right now. Like you are 2:29 allowed and explanation point, with end line (ENDL) 2:33 and our if statement. go ahead and write your two tests like 2:37 what did you put? age is greater than 21 and whenever you join them, 2:42 you use this logic ooperator "and 2:45 and" and now go ahead and write money 2:48 is greater than 500. now let's go ahead and run this and 2:51 check it out. same results, a whole lot less programming. 2:55 so what and and means, do this test 2:59 and do this test. if they're both 3:02 true then run this bit of code. And since they both were true 3:06 it ran this bit of code if one of them was false, say we only had, you know, 3:10 four dollars, like that, well yeah, this test is going to be true because we're greater 3:16 than twenty one 3:17 but this is going to be false, because four dollars is not greater than 500. #### 3:21 And whenever you run it we are not allowed in check it out 3:25 and also if both tests are false like 3:28 where only two and hopes or on space repair 3:33 say we're only two years old and we only have four dollars probably from tooth 3:36 fairy 3:37 of course we are not can be allowed in the club not cool but you know 3:42 were two year old who needs to go clubbin when they're too anyways so 3:45 basically a double and sign 3:47 means this test all these test and if they're both true 3:52 then you can run this bit of code by if one bomb is false 3:55 or both from this false then we don't run it support of our 3:59 and I say and with this test in this test 4:02 but you can also have and in another test 4:05 and even a man in another test and it's just gonna run all love your test 4:10 and make sure that they're all true so the only way this bit of coz gonna run 4:14 is a all your test in this is true 4:18 so over San re: I i understand that logic operator 4:21 all the tests need to be true in order to run but what if you say this 4:25 re: I am I you know not to most 4:28 fashion on my club owner so I'm gonna allow the man 4:32 if on the wannabes test is true if there are over 21 4:36 near loud and of course or if they have over five hundred dollars 4:40 I'm in a while allow men because you know fr 20-year-old walks and was like 4:45 a grand I know he's not 21 but I think we should let men anyways 4:50 so say we want to do that make sure only one of the test room 4:54 what we do is use a logical operator called the or 4:58 logical cooperator and thats if you see above the Enter key on your keyboard 5:02 in or shift you get these two little things I column pipe spa 5:06 I think some peeps comp I points teachers I don't know what they're 5:09 called 5:10 on it's like a straight line up and down as you can see 5:13 but settled ruler that's what it is and 5:17 to affirm in a row is to or large cooperator 5:21 in with the or large cooperator says is this 5:24 on like that and where this one and this one had to be true 5:28 only one of them has to be true in the other one can be false 5:31 and it still runs to the disco so check this out we pass this test is true 5:35 26 is greater than 21 but we don't have more than five hundred dollars so this 5:40 is gonna be false 0 true 5:42 and false so we run it and allows ascend even know 5:47 want these was false but if both these were false 5:51 see we're only six years old 5:55 it wouldn't allow sinn so anyways what you have to remember that 5:58 exist that and logical operator both the test have to be true 6:03 with or watch cooperator wanted it s have to be true 6:08 and another thing if both the tests are true in or 6:11 its gonna run your bit of code so that say you were you know 64 6:15 and you had you know a crap load of money it would Arron 6:19 in even though they're both true it would allow UN anyway so 6:22 with or this one or this one 6:26 or both won't have to be true and with hand 6:30 this one and this one has to be true and of course you can add another or 6:35 test and another or test 6:38 in another or test in when you're in program like this 6:42 is gonna run through all your test and as long as one woman's true for example 6:46 this one could be true 6:47 and all these other ones could be false you know still runs bit code 6:51 in or basically means look for at least one that's true 6:54 and if it's true run that code so now that I repeated that 6:58 about a hundred times you guys should understand difference between 7:02 and in or logical operator and when you do what one use one 7:06 versus the other I guess it depends on what can I call burning you want to be 7:09 but for now that saw the car bomb can do something else right in the store 7:14 arm done or uncovering next oral but if you click on an x-linked 7:17 you can see something cash watchin and I'll see you then