1
00:00:00,540 --> 00:00:01,620
Hello and welcome.

2
00:00:01,620 --> 00:00:07,940
In this lecture we are going to look at the basic arithmetic operators.

3
00:00:07,940 --> 00:00:17,280
We're going to look at the precedence that has to be applied when you use multiple operators together.

4
00:00:17,510 --> 00:00:18,050
Okay.

5
00:00:18,060 --> 00:00:20,220
So I'm just going to modify the code a little bit.

6
00:00:20,250 --> 00:00:21,870
I'm going to get rid of this line.

7
00:00:21,870 --> 00:00:24,260
We don't need that anymore.

8
00:00:24,330 --> 00:00:34,170
And here are going to change this variable I to do multiple calculations.

9
00:00:34,170 --> 00:00:36,090
So let's get rid of that.

10
00:00:36,090 --> 00:00:38,910
So I'm going to do say seven

11
00:00:41,970 --> 00:00:46,080
plus maybe three

12
00:00:49,290 --> 00:00:50,270
times

13
00:00:54,170 --> 00:00:55,010
five.

14
00:00:57,560 --> 00:00:58,300
OK.

15
00:00:58,340 --> 00:01:00,220
There are no squiggly red lines.

16
00:01:00,240 --> 00:01:02,120
I mean it should be all right.

17
00:01:02,120 --> 00:01:07,190
Anytime you see the yellow bits it means you haven't saved your code.

18
00:01:07,190 --> 00:01:10,080
So I would just say that.

19
00:01:10,280 --> 00:01:18,170
So if we were to run this code what do you think the answer would be.

20
00:01:18,170 --> 00:01:21,740
It will definitely not be.

21
00:01:21,830 --> 00:01:27,830
You might think it's going to be five times three 15 plus seven.

22
00:01:27,830 --> 00:01:28,160
Right.

23
00:01:28,190 --> 00:01:32,550
You might think that way but we'd operators.

24
00:01:32,570 --> 00:01:34,970
There is a precedence.

25
00:01:35,030 --> 00:01:44,910
So what happens is that the multiplication and the division will occur before the addition and subtraction.

26
00:01:44,930 --> 00:01:45,410
All right.

27
00:01:45,770 --> 00:01:54,860
So if I run this code you see that you will do the three times five first before add in the seven and

28
00:01:54,860 --> 00:01:56,510
not the other way around.

29
00:01:56,510 --> 00:01:57,740
So let me executed.

30
00:01:57,740 --> 00:01:58,580
So you can see.

31
00:02:00,030 --> 00:02:02,450
So if I click and go you should see the output.

32
00:02:02,450 --> 00:02:10,270
So it's giving me twenty two so which is three times five is 15 plus 7.

33
00:02:10,280 --> 00:02:17,870
So it has done the multiplication first before going on to the addition.

34
00:02:17,870 --> 00:02:21,300
So let me stop running the code and click on that to stop it.

35
00:02:21,890 --> 00:02:31,660
If I wanted the addition to be calculated first I need to wrap it round inside parentheses.

36
00:02:31,670 --> 00:02:36,730
I need to do something like this.

37
00:02:37,330 --> 00:02:40,390
That's the only way C Sharp will do it first.

38
00:02:40,390 --> 00:02:42,410
So what C Sharp will not do.

39
00:02:42,640 --> 00:02:47,700
It will add this first so it will be the answer will not be ten times five.

40
00:02:47,740 --> 00:02:50,950
So I'll expect the output to be 50.

41
00:02:50,950 --> 00:02:52,060
So I've got that saved.

42
00:02:52,060 --> 00:02:54,360
Let's run the code again so we can see.

43
00:02:55,820 --> 00:02:56,450
OK.

44
00:02:56,470 --> 00:03:00,100
So if I click that I should expect an output of 50.

45
00:03:00,660 --> 00:03:01,060
All right.

46
00:03:01,060 --> 00:03:10,000
Because I have specifically put a parent this is around that which means it will now be done calculated

47
00:03:10,000 --> 00:03:22,570
first before the multiplication in this lecture we experimented with some operator precedents where

48
00:03:22,660 --> 00:03:34,030
we observed that by default multiplication and division will occur before addition and subtraction in

49
00:03:34,030 --> 00:03:36,380
order for us to make the addition.

50
00:03:36,980 --> 00:03:39,150
You know compute.

51
00:03:39,160 --> 00:03:44,600
First we have to wrap or place it inside parentheses.

52
00:03:44,650 --> 00:03:45,580
That's the only way.

53
00:03:45,580 --> 00:03:47,680
Takes precedence over.

54
00:03:47,680 --> 00:03:52,860
The higher operators like multiplication and division.

55
00:03:52,870 --> 00:03:59,650
So whenever you want a certain calculation type in certain ways and you're playing around with basic

56
00:03:59,650 --> 00:04:03,150
operators whichever one you want calculated first.

57
00:04:03,190 --> 00:04:07,870
You just need to place them inside parentheses and it will do that first.

58
00:04:08,200 --> 00:04:10,260
So that's it for this lecture.

59
00:04:10,270 --> 00:04:12,400
Thanks so much for watching.

60
00:04:12,400 --> 00:04:12,990
Bye for now.
