[Script Info]
Title:
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.51,0:00:02.10,Default,,0000,0000,0000,,Okay.\NI'm going to just jump right in and
Dialogue: 0,0:00:02.10,0:00:03.63,Default,,0000,0000,0000,,hand simulate what's going on here.
Dialogue: 0,0:00:05.56,0:00:08.09,Default,,0000,0000,0000,,These first three lines we just\Ndeclare three variables and
Dialogue: 0,0:00:08.09,0:00:10.61,Default,,0000,0000,0000,,set them to initial values,\Nso I'm going to do that.
Dialogue: 0,0:00:11.67,0:00:13.66,Default,,0000,0000,0000,,Okay, so\Nthat's what that would look like.
Dialogue: 0,0:00:13.66,0:00:18.07,Default,,0000,0000,0000,,And then here in display,\NI'm saying display this arithmetic here.
Dialogue: 0,0:00:18.07,0:00:20.49,Default,,0000,0000,0000,,Let's look and\Nsee what the values of day 1, day 2, and
Dialogue: 0,0:00:20.49,0:00:23.11,Default,,0000,0000,0000,,day 3 are at this point in the program.
Dialogue: 0,0:00:23.11,0:00:24.04,Default,,0000,0000,0000,,Day 1 is 15.
Dialogue: 0,0:00:26.44,0:00:30.27,Default,,0000,0000,0000,,Day 2 is 22 and day 3 is 18.
Dialogue: 0,0:00:30.27,0:00:34.30,Default,,0000,0000,0000,,Now, this might seem a little bit silly\Nthat I went off here to the side and
Dialogue: 0,0:00:34.30,0:00:36.54,Default,,0000,0000,0000,,started keeping track\Nof these variables, but
Dialogue: 0,0:00:36.54,0:00:39.96,Default,,0000,0000,0000,,as the programs get more complicated and\Nvariables kind of change and
Dialogue: 0,0:00:39.96,0:00:44.77,Default,,0000,0000,0000,,get modified in this space, it's really\Nimportant to be keeping track of things.
Dialogue: 0,0:00:44.77,0:00:46.11,Default,,0000,0000,0000,,Anyways, the key insight for
Dialogue: 0,0:00:46.11,0:00:50.40,Default,,0000,0000,0000,,this problem is that you're doing\Nboth addition and a division here.
Dialogue: 0,0:00:50.40,0:00:53.70,Default,,0000,0000,0000,,Now, if you remember from when Katherine\Nwas talking about order of operation,
Dialogue: 0,0:00:53.70,0:00:55.98,Default,,0000,0000,0000,,division always comes before addition.
Dialogue: 0,0:00:55.98,0:00:59.22,Default,,0000,0000,0000,,Meaning the first thing that's going to\Nhappen is this division right here.
Dialogue: 0,0:00:59.22,0:01:01.82,Default,,0000,0000,0000,,So, 18 gets divided by 3, which is 6.
Dialogue: 0,0:01:01.82,0:01:06.50,Default,,0000,0000,0000,,And then we have 15 plus 22 plus 6,\Nwhich equals 43.
Dialogue: 0,0:01:06.50,0:01:08.61,Default,,0000,0000,0000,,So, it's going to print out 43.
Dialogue: 0,0:01:08.61,0:01:10.84,Default,,0000,0000,0000,,So, is that correct?
Dialogue: 0,0:01:10.84,0:01:12.74,Default,,0000,0000,0000,,Well, what we're trying to\Ndo is find the average.
Dialogue: 0,0:01:12.74,0:01:15.92,Default,,0000,0000,0000,,Finding the average involves\Nadding up all the numbers and
Dialogue: 0,0:01:15.92,0:01:18.21,Default,,0000,0000,0000,,then dividing by the number\Nof numbers you have.
Dialogue: 0,0:01:18.21,0:01:19.79,Default,,0000,0000,0000,,But we did the addition too early,
Dialogue: 0,0:01:19.79,0:01:22.63,Default,,0000,0000,0000,,we do it before we've added\Nup these three numbers.
Dialogue: 0,0:01:22.63,0:01:27.21,Default,,0000,0000,0000,,Really, it should be 15 plus 22\Nplus 18 then divided by three.
Dialogue: 0,0:01:27.21,0:01:28.78,Default,,0000,0000,0000,,So 43 is not the correct answer.
Dialogue: 0,0:01:30.02,0:01:31.79,Default,,0000,0000,0000,,And to make this code\Ndo the correct thing,
Dialogue: 0,0:01:31.79,0:01:34.78,Default,,0000,0000,0000,,you should be surrounding these\Nthree variables with parentheses.
Dialogue: 0,0:01:34.78,0:01:37.21,Default,,0000,0000,0000,,Then, you'll add 15 plus 22 plus 18.
Dialogue: 0,0:01:37.21,0:01:44.45,Default,,0000,0000,0000,,And then divide it by 3, which will give\Nyou the correct answer of about 18.3.