0:00:00.510,0:00:02.100
Okay.[br]I'm going to just jump right in and
0:00:02.100,0:00:03.630
hand simulate what's going on here.
0:00:05.560,0:00:08.090
These first three lines we just[br]declare three variables and
0:00:08.090,0:00:10.610
set them to initial values,[br]so I'm going to do that.
0:00:11.670,0:00:13.660
Okay, so[br]that's what that would look like.
0:00:13.660,0:00:18.070
And then here in display,[br]I'm saying display this arithmetic here.
0:00:18.070,0:00:20.491
Let's look and[br]see what the values of day 1, day 2, and
0:00:20.491,0:00:23.110
day 3 are at this point in the program.
0:00:23.110,0:00:24.044
Day 1 is 15.
0:00:26.440,0:00:30.270
Day 2 is 22 and day 3 is 18.
0:00:30.270,0:00:34.300
Now, this might seem a little bit silly[br]that I went off here to the side and
0:00:34.300,0:00:36.540
started keeping track[br]of these variables, but
0:00:36.540,0:00:39.960
as the programs get more complicated and[br]variables kind of change and
0:00:39.960,0:00:44.770
get modified in this space, it's really[br]important to be keeping track of things.
0:00:44.770,0:00:46.110
Anyways, the key insight for
0:00:46.110,0:00:50.400
this problem is that you're doing[br]both addition and a division here.
0:00:50.400,0:00:53.700
Now, if you remember from when Katherine[br]was talking about order of operation,
0:00:53.700,0:00:55.980
division always comes before addition.
0:00:55.980,0:00:59.220
Meaning the first thing that's going to[br]happen is this division right here.
0:00:59.220,0:01:01.820
So, 18 gets divided by 3, which is 6.
0:01:01.820,0:01:06.500
And then we have 15 plus 22 plus 6,[br]which equals 43.
0:01:06.500,0:01:08.610
So, it's going to print out 43.
0:01:08.610,0:01:10.840
So, is that correct?
0:01:10.840,0:01:12.740
Well, what we're trying to[br]do is find the average.
0:01:12.740,0:01:15.920
Finding the average involves[br]adding up all the numbers and
0:01:15.920,0:01:18.208
then dividing by the number[br]of numbers you have.
0:01:18.208,0:01:19.790
But we did the addition too early,
0:01:19.790,0:01:22.630
we do it before we've added[br]up these three numbers.
0:01:22.630,0:01:27.210
Really, it should be 15 plus 22[br]plus 18 then divided by three.
0:01:27.210,0:01:28.780
So 43 is not the correct answer.
0:01:30.020,0:01:31.790
And to make this code[br]do the correct thing,
0:01:31.790,0:01:34.780
you should be surrounding these[br]three variables with parentheses.
0:01:34.780,0:01:37.210
Then, you'll add 15 plus 22 plus 18.
0:01:37.210,0:01:44.449
And then divide it by 3, which will give[br]you the correct answer of about 18.3.