Hello and welcome.
In this lecture we are going to look at the basic arithmetic operators.
We're going to look at the precedence that has to be applied when you use multiple operators together.
Okay.
So I'm just going to modify the code a little bit.
I'm going to get rid of this line.
We don't need that anymore.
And here are going to change this variable I to do multiple calculations.
So let's get rid of that.
So I'm going to do say seven
plus maybe three
times
five.
OK.
There are no squiggly red lines.
I mean it should be all right.
Anytime you see the yellow bits it means you haven't saved your code.
So I would just say that.
So if we were to run this code what do you think the answer would be.
It will definitely not be.
You might think it's going to be five times three 15 plus seven.
Right.
You might think that way but we'd operators.
There is a precedence.
So what happens is that the multiplication and the division will occur before the addition and subtraction.
All right.
So if I run this code you see that you will do the three times five first before add in the seven and
not the other way around.
So let me executed.
So you can see.
So if I click and go you should see the output.
So it's giving me twenty two so which is three times five is 15 plus 7.
So it has done the multiplication first before going on to the addition.
So let me stop running the code and click on that to stop it.
If I wanted the addition to be calculated first I need to wrap it round inside parentheses.
I need to do something like this.
That's the only way C Sharp will do it first.
So what C Sharp will not do.
It will add this first so it will be the answer will not be ten times five.
So I'll expect the output to be 50.
So I've got that saved.
Let's run the code again so we can see.
OK.
So if I click that I should expect an output of 50.
All right.
Because I have specifically put a parent this is around that which means it will now be done calculated
first before the multiplication in this lecture we experimented with some operator precedents where
we observed that by default multiplication and division will occur before addition and subtraction in
order for us to make the addition.
You know compute.
First we have to wrap or place it inside parentheses.
That's the only way.
Takes precedence over.
The higher operators like multiplication and division.
So whenever you want a certain calculation type in certain ways and you're playing around with basic
operators whichever one you want calculated first.
You just need to place them inside parentheses and it will do that first.
So that's it for this lecture.
Thanks so much for watching.
Bye for now.