1 00:00:15,126 --> 00:00:15,696 >> Hello, everybody. 2 00:00:15,696 --> 00:00:18,516 Welcome to the Walkthrough One, my name is Tommy MacWilliam, 3 00:00:18,516 --> 00:00:22,486 and today we're going to be over our PSET 1, which is on C. 4 00:00:23,296 --> 00:00:26,056 So the music I hypothetically would have played before the 5 00:00:26,056 --> 00:00:29,296 walkthrough, so first I just want to talk a little bit 6 00:00:29,296 --> 00:00:31,246 about grading, so PSETs you're going 7 00:00:31,276 --> 00:00:33,946 to be graded along four different axis. 8 00:00:34,146 --> 00:00:37,106 The first is scope, and this is basically how much 9 00:00:37,106 --> 00:00:38,466 of the PSET did you complete? 10 00:00:38,466 --> 00:00:41,326 So make us a program that has three features. 11 00:00:41,326 --> 00:00:43,166 Did you do all three of them and did all three 12 00:00:43,166 --> 00:00:44,726 of them do what they're supposed to do? 13 00:00:45,286 --> 00:00:48,186 Next is correctness, so did you program have any bugs? 14 00:00:48,346 --> 00:00:49,426 Can we crash it somehow? 15 00:00:49,426 --> 00:00:51,466 Does it not behave the way it's supposed to? 16 00:00:51,466 --> 00:00:54,426 Next is design, and this is kind of the broadest. 17 00:00:54,636 --> 00:00:55,996 Is it well designed? 18 00:00:56,186 --> 00:00:57,356 Does it work efficiently? 19 00:00:57,356 --> 00:00:59,466 Did you make good code design decisions? 20 00:00:59,776 --> 00:01:00,566 This is where you're going 21 00:01:00,566 --> 00:01:03,576 to get the most qualitative learning experience 22 00:01:03,576 --> 00:01:04,296 out of the course. 23 00:01:04,696 --> 00:01:07,386 And finally is style, and this is how does it look? 24 00:01:07,386 --> 00:01:08,536 Is it commented well? 25 00:01:08,536 --> 00:01:11,836 Did you indent well, did you name your variables a good name 26 00:01:12,256 --> 00:01:14,056 and things like that. 27 00:01:14,056 --> 00:01:17,446 So any questions on the axis and how they'll be graded? 28 00:01:18,436 --> 00:01:21,436 So you'll be graded on a scale of one to five, 29 00:01:21,956 --> 00:01:25,356 so where five is best, one is not so great and three is right 30 00:01:25,356 --> 00:01:27,246 in the middle, so that would be good. 31 00:01:27,476 --> 00:01:30,506 So on each of your PSETs you'll get back with each of those axis 32 00:01:30,506 --> 00:01:33,346 and associated score and then we'll at the end of the term add 33 00:01:33,976 --> 00:01:36,546 up all those scores and see where you end up relative 34 00:01:36,546 --> 00:01:38,496 to yourself in week zero. 35 00:01:38,956 --> 00:01:41,646 So any questions on grading? 36 00:01:41,646 --> 00:01:43,266 I know you haven't gotten any grades back yet, 37 00:01:43,266 --> 00:01:44,776 but before you do any questions? 38 00:01:45,406 --> 00:01:49,976 So as I'm talking feel free to interrupt me with questions. 39 00:01:49,976 --> 00:01:52,216 Don't wait until I pause, it's much more fun that way. 40 00:01:53,686 --> 00:01:55,986 So before we get started, we're going to need a few things. 41 00:01:56,326 --> 00:01:59,956 The first is the CS50 appliance which we've seen in lecture. 42 00:02:00,166 --> 00:02:02,136 It's basically the environment in which you're going 43 00:02:02,136 --> 00:02:03,336 to be working with your code. 44 00:02:03,336 --> 00:02:05,566 It's kind of a computer within a computer. 45 00:02:05,976 --> 00:02:09,266 And it looks like this. 46 00:02:09,486 --> 00:02:14,956 So once you download it from manual.cs50.net/appliance, 47 00:02:14,956 --> 00:02:17,886 you're going to open up virtual box 48 00:02:18,126 --> 00:02:21,566 and you'll see a little thing that says CS50 appliance 2.3 49 00:02:21,756 --> 00:02:25,836 and then you can click show and then it's going to fire 50 00:02:25,836 --> 00:02:28,326 up a little Lenox desktop. 51 00:02:28,486 --> 00:02:30,936 So this is just like an operating system just 52 00:02:30,936 --> 00:02:33,836 like Windows or Mac, and this is just so everyone is working 53 00:02:33,836 --> 00:02:36,226 with the same operating system and has the same tools 54 00:02:36,226 --> 00:02:37,406 as they're writing their code. 55 00:02:37,926 --> 00:02:42,426 So to get out of the appliance you'll notice once you click 56 00:02:42,426 --> 00:02:44,976 into it you have control of the mouse inside of the appliance 57 00:02:45,306 --> 00:02:47,526 and to get out of it you want to click the host key, 58 00:02:47,526 --> 00:02:48,896 which on Mac is the left command, 59 00:02:49,126 --> 00:02:51,306 and the first time you write it it'll get a little popup 60 00:02:51,386 --> 00:02:53,066 that says this is your host key, 61 00:02:53,226 --> 00:02:55,106 but that's what it's referring to, just this key you press 62 00:02:55,426 --> 00:02:56,946 to get your mouse pointer back. 63 00:02:57,126 --> 00:02:57,316 Sure. 64 00:02:57,316 --> 00:03:00,886 >> I started [inaudible] the virtual box in it and asked 65 00:03:01,006 --> 00:03:03,226 for a name and I got confused 66 00:03:03,746 --> 00:03:08,246 because the instructions said [inaudible] Harvard 67 00:03:08,526 --> 00:03:11,796 and I thought am I going into [inaudible] Harvard 68 00:03:11,796 --> 00:03:15,726 and give it my name or - I wasn't sure if I had 69 00:03:15,726 --> 00:03:17,256 to do that early or -- 70 00:03:17,396 --> 00:03:19,516 >> So when you're installing it asked for a name? 71 00:03:19,966 --> 00:03:24,016 so that's interesting, if you're just installing the actual 72 00:03:24,016 --> 00:03:25,796 appliance itself the name is probably just left 73 00:03:25,796 --> 00:03:28,936 as CS50 appliance 2.3 or something like that. 74 00:03:29,066 --> 00:03:30,846 It shouldn't matter what you name the actual appliance 75 00:03:30,916 --> 00:03:34,006 but the user inside of that is going to be J Harvard. 76 00:03:34,006 --> 00:03:36,786 So just like you log in onto your laptop with some user name, 77 00:03:36,976 --> 00:03:38,796 that's the user that's in the appliance created 78 00:03:38,796 --> 00:03:40,076 for you is called J. Harvard. 79 00:03:40,626 --> 00:03:42,846 So if you have any troubleshooting issues, 80 00:03:43,156 --> 00:03:46,716 we have two pages on our CS50 manual. 81 00:03:46,716 --> 00:03:50,046 One is the appliance in general, like how to use the appliance, 82 00:03:50,046 --> 00:03:52,746 what its IP is, how to do things like text editing, 83 00:03:52,936 --> 00:03:53,966 and the second page is just 84 00:03:53,966 --> 00:03:57,266 for installation troubleshooting issues for Mac and Windows. 85 00:03:57,986 --> 00:04:00,056 And if you have an issue that's not on either one 86 00:04:00,056 --> 00:04:03,626 of these pages, just feel free to post to help.cs50.net 87 00:04:03,626 --> 00:04:06,206 and then someone from the staff will respond and make sure 88 00:04:06,206 --> 00:04:08,626 that you're good to go before you start the PSET. 89 00:04:09,626 --> 00:04:11,536 So inside of the appliance we're going 90 00:04:11,536 --> 00:04:14,666 to be using a program called gedit or Gedit, whichever it is, 91 00:04:14,926 --> 00:04:17,086 and so this is just a text editor. 92 00:04:17,086 --> 00:04:19,416 It's where you're going to be writing all of your source code 93 00:04:19,416 --> 00:04:24,336 and save the dotc files and then you can run these programs 94 00:04:24,336 --> 00:04:26,226 that you write inside of the terminal. 95 00:04:26,476 --> 00:04:28,876 So it's both a standalone program in the appliance 96 00:04:29,196 --> 00:04:31,346 or the way we've set up gedit just 97 00:04:31,346 --> 00:04:33,326 at the bottom there there's a little mini terminal 98 00:04:33,326 --> 00:04:35,196 where you can do things like compile your code 99 00:04:35,196 --> 00:04:37,076 and run your code and do all of your testing. 100 00:04:37,076 --> 00:04:38,756 So you don't even need to leave you're text editor 101 00:04:38,756 --> 00:04:39,906 to actually run your program. 102 00:04:40,856 --> 00:04:42,566 and finally this week we're going 103 00:04:42,566 --> 00:04:43,896 to be using something called make, 104 00:04:43,896 --> 00:04:46,756 and this just basically makes the compilation process, 105 00:04:46,756 --> 00:04:49,706 taking your C-code and creating machine code that the -- 106 00:04:49,706 --> 00:04:50,786 your computer can run 107 00:04:51,066 --> 00:04:53,356 and it just makes this process really, really simple. 108 00:04:53,356 --> 00:04:57,176 So let's actually take a look at what this process would be. 109 00:04:57,896 --> 00:04:59,296 So the first thing you're asked to do 110 00:04:59,296 --> 00:05:02,836 in your PSET is write a little program called Hello.seek, 111 00:05:03,376 --> 00:05:05,066 so it's a three-step process to do this. 112 00:05:05,066 --> 00:05:07,156 One we're going to actually write the dotc file 113 00:05:07,446 --> 00:05:09,946 and have the source code that says hello world 114 00:05:09,946 --> 00:05:12,316 or whatever we want it to say and then we need to take 115 00:05:12,316 --> 00:05:14,766 that source code and translate it into object code 116 00:05:14,766 --> 00:05:16,486 or machine code, the zeros and ones 117 00:05:16,486 --> 00:05:17,806 that your computer can understand. 118 00:05:18,136 --> 00:05:20,536 And to do that we're going to run make hello, 119 00:05:20,756 --> 00:05:23,276 and this is going to be inside of our little terminal, 120 00:05:23,276 --> 00:05:25,006 inside of gedit and finally 121 00:05:25,006 --> 00:05:27,626 to run it we're going to say dot/hello. 122 00:05:27,936 --> 00:05:30,716 That just says that there's a program called hello inside 123 00:05:30,716 --> 00:05:32,246 of the folder that I'm looking at right now 124 00:05:32,496 --> 00:05:34,326 and I want you to run it. 125 00:05:34,326 --> 00:05:36,346 So let's take a look at how we will do that. 126 00:05:37,246 --> 00:05:40,766 So here we go, inside of the appliance I'm going to go 127 00:05:41,366 --> 00:05:46,976 to menu, programming, and then I have gedit right here. 128 00:05:47,176 --> 00:05:52,706 I also have a shortcut right there, so once I open it we need 129 00:05:52,706 --> 00:05:54,536 to write our first c program. 130 00:05:54,926 --> 00:05:57,296 So what's the first thing we need to do in our c program? 131 00:05:57,296 --> 00:05:57,866 >> [Inaudible] 132 00:05:57,866 --> 00:06:02,796 >> So a lot of different things because there are a lot 133 00:06:02,796 --> 00:06:04,036 of different things we can do first. 134 00:06:04,296 --> 00:06:08,296 The correct answer is write a comment that says what it is, 135 00:06:08,296 --> 00:06:11,356 what your name is, what the name of the program is, what it does. 136 00:06:11,596 --> 00:06:14,896 So I'm just going to say hello.c write my name, 137 00:06:15,616 --> 00:06:21,116 and now we need to do two things. 138 00:06:21,116 --> 00:06:23,746 We need to include some libraries that allow us 139 00:06:23,746 --> 00:06:26,826 to use functions like print out and we also need 140 00:06:26,826 --> 00:06:29,046 to actually write the program. 141 00:06:29,156 --> 00:06:30,306 So which of those is first? 142 00:06:30,306 --> 00:06:31,676 Do we need o pull in the libraries first 143 00:06:31,676 --> 00:06:33,946 or can we just get right into it and include the libraries later? 144 00:06:33,946 --> 00:06:34,396 >> [Inaudible] 145 00:06:34,396 --> 00:06:38,276 >> Right. So we first need to include the libraries, 146 00:06:38,276 --> 00:06:42,516 so it's going to be pound include and then inside 147 00:06:42,516 --> 00:06:46,586 of these angle brackets we're going to say standard io.h. 148 00:06:46,916 --> 00:06:48,546 So this is basically some file 149 00:06:48,666 --> 00:06:51,436 that some really nice person wrote for us and gave it to us 150 00:06:51,496 --> 00:06:52,976 for free and it contains a lot 151 00:06:52,976 --> 00:06:55,546 of really handy functions relating to input and output. 152 00:06:55,976 --> 00:06:58,696 So getting users input, so having them type something 153 00:06:58,696 --> 00:06:59,956 and then outputting it, 154 00:07:00,056 --> 00:07:02,006 so displaying something in the terminal. 155 00:07:02,396 --> 00:07:04,426 So now that I've included the library that I need, 156 00:07:04,606 --> 00:07:06,606 what do I do right next? 157 00:07:09,456 --> 00:07:13,016 So now we need to write our main functions, so the net point 158 00:07:13,046 --> 00:07:15,366 for our program, so when the machine runs it's going to look 159 00:07:15,366 --> 00:07:17,326 for something called main that's going to say okay, 160 00:07:17,326 --> 00:07:18,946 I'm going to run this thing called main. 161 00:07:19,296 --> 00:07:23,916 So we're going to say ent main, doesn't take any arguments 162 00:07:23,916 --> 00:07:25,996 which we'll learn about later, and now -- 163 00:07:26,086 --> 00:07:30,536 whoa, here's where I can actually write what I want 164 00:07:30,536 --> 00:07:31,716 to display to the user. 165 00:07:31,716 --> 00:07:33,816 So let's say I just want to output some message 166 00:07:33,816 --> 00:07:36,126 onto the terminal, how can I do that? 167 00:07:36,616 --> 00:07:37,606 >> Print it. 168 00:07:37,876 --> 00:07:38,866 >> Printout, exactly. 169 00:07:38,866 --> 00:07:41,986 So we're going to say print and then inside 170 00:07:41,986 --> 00:07:44,376 of the parenthesis we're going to tell it what to print. 171 00:07:44,746 --> 00:07:46,946 So we can just print off hello 172 00:07:47,346 --> 00:07:50,326 and now what is this forward slash end thing? 173 00:07:51,376 --> 00:07:54,326 A new line, exactly, so if I didn't have this new line I 174 00:07:54,326 --> 00:07:55,646 would basically say hello 175 00:07:55,646 --> 00:07:58,316 and then it would awkwardly say J. Harvard appliance 176 00:07:58,316 --> 00:07:59,816 after that instead of having that be 177 00:07:59,816 --> 00:08:01,486 on its own line like it usually is. 178 00:08:01,806 --> 00:08:04,326 So we include that new line so our program doesn't look awkward 179 00:08:04,326 --> 00:08:07,366 when it's all done, and now what else do I need on this line, 180 00:08:07,366 --> 00:08:09,886 one more thing, a semicolon, exactly. 181 00:08:09,886 --> 00:08:12,126 So we need to make sure that every statement 182 00:08:12,126 --> 00:08:14,166 in our C program, like a function call 183 00:08:14,166 --> 00:08:16,356 or a variable assignment or anything like that ends 184 00:08:16,356 --> 00:08:19,946 in a semicolon and if not then make is going to yell at you 185 00:08:19,946 --> 00:08:20,856 and you'll feel badly. 186 00:08:22,076 --> 00:08:24,436 So now once our program is written we're going 187 00:08:24,436 --> 00:08:24,996 to go to file. 188 00:08:25,436 --> 00:08:26,206 We can save it. 189 00:08:26,296 --> 00:08:29,636 I'm just going to call it hello.c, 190 00:08:29,636 --> 00:08:32,316 so I'll just save it in my home folder. 191 00:08:32,316 --> 00:08:36,696 So now it's saved and you'll notice that get it recognized, 192 00:08:36,696 --> 00:08:39,756 it's a c file and we now have the syntax highlighting. 193 00:08:39,756 --> 00:08:42,306 So different words are colored differently depending 194 00:08:42,306 --> 00:08:43,376 on what they mean. 195 00:08:44,736 --> 00:08:48,306 So now I can come down here at the bottom into my terminal. 196 00:08:48,666 --> 00:08:50,276 So it says J. Harvard at appliance, 197 00:08:50,436 --> 00:08:52,286 so this is just the user you're logged into, 198 00:08:52,286 --> 00:08:53,616 which I mentioned is J. Harvard, 199 00:08:53,846 --> 00:08:55,826 the at and then the machine name. 200 00:08:55,826 --> 00:08:59,186 So this is the CS50 appliance, so it's J. Harvard at appliance. 201 00:08:59,706 --> 00:09:01,946 So now I want to type make hello. 202 00:09:01,946 --> 00:09:07,766 I click enter and there we go. 203 00:09:07,826 --> 00:09:10,776 So it ran this GCC thing for us, 204 00:09:11,216 --> 00:09:12,886 which basically compiles our code 205 00:09:12,886 --> 00:09:16,546 into a program called hello, so now if I want to list 206 00:09:16,546 --> 00:09:18,246 out everything that I have inside 207 00:09:18,246 --> 00:09:21,366 of this folder I can just type LS and hit enter 208 00:09:21,366 --> 00:09:23,756 and now you can see that I have a desktop folder, 209 00:09:23,756 --> 00:09:27,036 I have a folder for the walkthrough, here's my hello.c 210 00:09:27,206 --> 00:09:29,246 and now here's this extra thing hello. 211 00:09:29,496 --> 00:09:32,006 And so this is the program that we just wrote. 212 00:09:32,256 --> 00:09:38,106 So I can say do slash hello hit enter and there we go. 213 00:09:38,836 --> 00:09:39,226 Question? 214 00:09:39,886 --> 00:09:39,976 >> How [inaudible] 215 00:09:40,316 --> 00:09:45,156 >> You're getting -- so what else does it say? 216 00:09:45,756 --> 00:09:48,136 >> It says name [inaudible] 217 00:09:49,716 --> 00:09:53,516 >> So if you're getting error one I'd have to look 218 00:09:53,516 --> 00:09:55,046 at so I know what error one is. 219 00:09:55,046 --> 00:09:58,256 So just make sure that your file looks exactly like this. 220 00:09:58,256 --> 00:10:00,406 You might be forgetting a semicolon somewhere 221 00:10:00,406 --> 00:10:03,196 or misspelled something but I can take a look 222 00:10:03,196 --> 00:10:04,896 at it right afterwards and help you out with that. 223 00:10:05,796 --> 00:10:08,986 Yeah. So generally the error message will include some number 224 00:10:08,986 --> 00:10:10,786 in it, like it will have a colon and then some number 225 00:10:10,786 --> 00:10:13,616 and that's usually the line number in your file, 226 00:10:13,616 --> 00:10:14,676 where you have your error. 227 00:10:16,026 --> 00:10:16,646 So other questions? 228 00:10:16,646 --> 00:10:16,846 Yep? 229 00:10:17,586 --> 00:10:20,536 >> It says [inaudible] file directory [inaudible] directory? 230 00:10:20,736 --> 00:10:22,946 >> So if it says no such file 231 00:10:22,946 --> 00:10:25,116 in directory how do you make sure you know where you are? 232 00:10:25,966 --> 00:10:29,656 So we also have a built-in file manager, so if you go over here 233 00:10:29,656 --> 00:10:33,146 to menu and then system and oh, 234 00:10:34,216 --> 00:10:37,446 so soon our file manager this is the equivalent of something 235 00:10:37,446 --> 00:10:41,626 like Windows explorer or finder on a Mac, and it's going to open 236 00:10:41,786 --> 00:10:43,236 up into your home directory. 237 00:10:43,236 --> 00:10:44,736 So over here I click on J. Harvard, 238 00:10:44,736 --> 00:10:47,816 and this is my home directory so you notice I have my hello 239 00:10:47,816 --> 00:10:50,446 and my hello.c inside of this directory. 240 00:10:50,746 --> 00:10:53,386 Now if I wanted to get into the walkthrough one directory 241 00:10:53,636 --> 00:10:57,216 from the terminal, I'm going to type in CD 242 00:10:57,526 --> 00:10:59,806 for a change directory and then the name 243 00:10:59,806 --> 00:11:02,236 of the directory I want to change to. 244 00:11:02,626 --> 00:11:04,676 So I can start typing walkthrough. 245 00:11:04,676 --> 00:11:07,086 If you hit tab it's actually going to auto complete for you 246 00:11:07,086 --> 00:11:09,976 so I just type wa tab and it auto completed walkthrough, 247 00:11:09,976 --> 00:11:12,366 and now I hit enter and you notice 248 00:11:12,366 --> 00:11:15,426 that now it says J. Harvard at appliance and now we're inside 249 00:11:15,426 --> 00:11:16,956 of the walkthrough directory. 250 00:11:17,496 --> 00:11:19,106 So that little tilde at the beginning 251 00:11:19,106 --> 00:11:22,956 that just signified the home directory, so J. Harvard's home 252 00:11:23,256 --> 00:11:27,256 and so now if I do an LS I can see a different set of files. 253 00:11:27,726 --> 00:11:28,716 So no longer -- well, 254 00:11:28,716 --> 00:11:30,436 I do actually have another file called hello there 255 00:11:30,506 --> 00:11:32,166 but it's a different file than the one 256 00:11:32,396 --> 00:11:34,006 that I have inside of my home directory. 257 00:11:34,566 --> 00:11:36,746 So if we want to get back there we can do a couple of things. 258 00:11:36,746 --> 00:11:40,386 We can do CD tilde, so we can go to my home directory 259 00:11:40,386 --> 00:11:45,256 so like my documents or my documents folder, or if I want 260 00:11:45,256 --> 00:11:48,146 to go up a directory I can say CD dot dot. 261 00:11:48,836 --> 00:11:49,586 That's going to say go 262 00:11:49,586 --> 00:11:51,706 to the directory that's immediately above mine. 263 00:11:51,926 --> 00:11:54,206 So we just went into one folder now we're going to go up out 264 00:11:54,206 --> 00:11:57,596 of that folder and we're back here with my hello. 265 00:11:58,146 --> 00:12:01,346 So you see more on that in the super section 266 00:12:01,346 --> 00:12:04,516 if you haven't already, but any questions on how we're going 267 00:12:04,516 --> 00:12:07,466 to compile our code and start running it. 268 00:12:09,196 --> 00:12:10,716 >> What does LS mean? 269 00:12:11,326 --> 00:12:12,376 >> So what is LS mean? 270 00:12:12,376 --> 00:12:15,786 So LS is to list all the files inside of the current directory, 271 00:12:16,166 --> 00:12:17,956 so now I'm inside of home, I say LS 272 00:12:18,246 --> 00:12:19,166 and I'm going to list them all. 273 00:12:19,606 --> 00:12:21,116 If I want a list of all the files inside 274 00:12:21,116 --> 00:12:23,576 of a different folder I and just CD to that folder 275 00:12:23,576 --> 00:12:25,486 and then type LS again and it's going 276 00:12:25,486 --> 00:12:26,456 to be a different set of files. 277 00:12:27,046 --> 00:12:31,776 >> Can you scroll up to the top [inaudible] in looking 278 00:12:32,616 --> 00:12:35,276 around definitely [inaudible] 279 00:12:35,276 --> 00:12:38,286 >> So this is called a comet, so when the compiler is going 280 00:12:38,286 --> 00:12:41,396 to actually translate your code to the object code, 281 00:12:41,396 --> 00:12:42,466 so the machine code that's going 282 00:12:42,466 --> 00:12:44,386 to be run the first thing it's' going to do is that. 283 00:12:45,056 --> 00:12:46,796 It's going to delete everything in a comment, 284 00:12:47,056 --> 00:12:50,456 but as programmers, it's really good to know, you know, 285 00:12:50,456 --> 00:12:52,886 what this file does, who wrote it in addition 286 00:12:52,886 --> 00:12:55,546 to what every line or not every line 287 00:12:55,546 --> 00:12:57,986 but what the main parts of our program are. 288 00:12:58,146 --> 00:12:59,896 So we'll see more about that shortly. 289 00:12:59,996 --> 00:13:02,066 But whenever you write a program it's really good 290 00:13:02,066 --> 00:13:04,826 to have your name, the date, what the program does 291 00:13:04,826 --> 00:13:05,886 at the very top of it. 292 00:13:07,086 --> 00:13:07,336 Yep? 293 00:13:07,586 --> 00:13:10,286 >> Do we have to use a [inaudible] series 294 00:13:10,876 --> 00:13:11,036 before [inaudible]? 295 00:13:11,186 --> 00:13:13,416 >> So do we have to use an asterix before every line 296 00:13:13,416 --> 00:13:13,936 of our comment? 297 00:13:13,936 --> 00:13:15,876 So this is just kind of a convention, 298 00:13:16,186 --> 00:13:19,976 so a multiline comment has to be enclosed 299 00:13:19,976 --> 00:13:21,786 between these two things. 300 00:13:22,076 --> 00:13:25,396 So anything inside of the slash star and the star slash, 301 00:13:25,696 --> 00:13:27,506 this is going to be immediately deleted 302 00:13:27,506 --> 00:13:28,776 as soon as we run our code. 303 00:13:29,146 --> 00:13:31,546 But there are kind of notes to ourselves as programmers 304 00:13:31,546 --> 00:13:33,596 and notes to anyone else who might read our code 305 00:13:33,806 --> 00:13:35,196 about what the program does. 306 00:13:35,196 --> 00:13:38,276 So I just think it looks pretty if you have stars in every line, 307 00:13:38,736 --> 00:13:40,786 but that's not strictly required no. 308 00:13:41,266 --> 00:13:41,366 yep? 309 00:13:43,096 --> 00:13:44,556 >> [Inaudible] one line? 310 00:13:44,876 --> 00:13:47,456 >> So how do you do a single line comment? 311 00:13:47,456 --> 00:13:49,306 So that's just going to be slash slash 312 00:13:49,666 --> 00:13:52,936 so I can say slash slash what comment. 313 00:13:53,336 --> 00:13:54,836 So this is a multiline comment, 314 00:13:54,836 --> 00:14:00,856 and this is a single-line comment. 315 00:14:01,586 --> 00:14:04,706 Other questions? 316 00:14:05,686 --> 00:14:06,746 All right. 317 00:14:09,116 --> 00:14:17,476 So speaking of commenting, code style means a lot to me. 318 00:14:17,616 --> 00:14:19,426 It's near and dear to my heart. 319 00:14:19,426 --> 00:14:21,096 And so really as far as you're concerned 320 00:14:21,096 --> 00:14:22,686 in your PSETs they're like free points. 321 00:14:22,966 --> 00:14:24,926 If you pay attention to your style, 322 00:14:24,926 --> 00:14:26,306 you have everything will intended 323 00:14:26,306 --> 00:14:28,846 and commented it's literally free points 324 00:14:29,086 --> 00:14:31,286 and it really does mean a lot to me personally. 325 00:14:31,726 --> 00:14:34,756 So to help you with your style, 326 00:14:34,756 --> 00:14:36,796 we put together the CS50 style guide. 327 00:14:37,446 --> 00:14:40,946 So if you just go to manual.cs50.net/style, 328 00:14:40,946 --> 00:14:44,776 you have this whole list of things that we would like you 329 00:14:44,776 --> 00:14:47,336 to do and things that we would not like you to do. 330 00:14:47,466 --> 00:14:49,286 So before the first PSET, 331 00:14:49,286 --> 00:14:51,046 this is definitely worth a read-through. 332 00:14:51,936 --> 00:14:53,806 But the most important thing with regard 333 00:14:53,806 --> 00:14:55,556 to code style is consistency 334 00:14:56,066 --> 00:14:58,666 so if you're consistently naming variables 335 00:14:58,666 --> 00:15:01,656 with underscores instead of capital letters you want to d 336 00:15:01,656 --> 00:15:02,866 that everywhere in your program. 337 00:15:02,866 --> 00:15:05,886 we don't want to see like my underscore variable 338 00:15:05,886 --> 00:15:08,716 and then my capital V variable in the same program, 339 00:15:08,716 --> 00:15:09,656 you want to be consistent. 340 00:15:09,946 --> 00:15:12,286 Make sure indentation is also consistent; 341 00:15:12,286 --> 00:15:13,696 don't use four spaces somewhere 342 00:15:13,696 --> 00:15:16,556 and then eight tabs somewhere else, and the same thing 343 00:15:16,556 --> 00:15:17,506 with your brakes placement. 344 00:15:17,506 --> 00:15:19,416 If you want to put them on a new line, that's cool, 345 00:15:19,416 --> 00:15:21,246 if you want to put them on the same line that's cool, 346 00:15:21,386 --> 00:15:23,916 just be condiment throughout all your programs. 347 00:15:24,846 --> 00:15:25,146 Yep? 348 00:15:25,706 --> 00:15:27,996 >> [Inaudible] should we use for [inaudible] 349 00:15:28,506 --> 00:15:30,796 >> So for indenting should we use four spaces or a tab? 350 00:15:31,076 --> 00:15:33,506 I think it's going to default to four spaces, 351 00:15:33,906 --> 00:15:36,196 which I think is what the style guide also recommends, 352 00:15:36,436 --> 00:15:37,716 but you can use something else as long 353 00:15:37,716 --> 00:15:40,266 as you're consistent then that's all we're looking for. 354 00:15:40,826 --> 00:15:42,966 Other questions? 355 00:15:43,336 --> 00:15:43,706 All right. 356 00:15:44,536 --> 00:15:54,786 So oh so we have a couple examples of code style here, 357 00:15:54,786 --> 00:16:05,196 so I'm going to open up two files 358 00:16:07,436 --> 00:16:12,086 so let me scroll down a little bit. 359 00:16:12,196 --> 00:16:15,706 So here is our first example, so let me just knock 360 00:16:15,706 --> 00:16:19,146 down the font a little bit. 361 00:16:22,706 --> 00:16:24,036 Okay. so this is what we're talking 362 00:16:24,036 --> 00:16:25,596 about when we mean good style. 363 00:16:25,976 --> 00:16:29,106 So you notice here at the top we have a program what's called 364 00:16:29,806 --> 00:16:32,636 who wrote it, and then the purpose of this program is 365 00:16:32,636 --> 00:16:34,466 to demonstrate good style and so that's it 366 00:16:34,466 --> 00:16:35,286 for the top of the harder. 367 00:16:36,146 --> 00:16:38,676 Next we have our includes, so now you'll notice 368 00:16:38,676 --> 00:16:40,536 that I have the single-line comments 369 00:16:40,536 --> 00:16:43,176 that describe what blocks of code do, 370 00:16:43,516 --> 00:16:45,446 so iterations equals get it, 371 00:16:45,496 --> 00:16:47,786 that doesn't really mean anything without the comment, 372 00:16:47,786 --> 00:16:50,706 but now if I say ask the user how many iterations that I want, 373 00:16:50,906 --> 00:16:53,126 now I say okay, so that's what that line of code that means. 374 00:16:54,086 --> 00:16:57,086 So next I have an if else, you notice the braces are 375 00:16:57,086 --> 00:16:59,566 on their own line, the indentation is consistent 376 00:16:59,716 --> 00:17:02,426 and we have a comment above this block explaining what it's 377 00:17:02,426 --> 00:17:02,866 there for. 378 00:17:03,806 --> 00:17:07,026 And finally the same thing with our loop, and then we end. 379 00:17:07,556 --> 00:17:10,016 So this is what I would consider good code style, 380 00:17:10,076 --> 00:17:11,886 we're consistent we have commencing, 381 00:17:12,056 --> 00:17:14,966 we named our variables good things like iterations, 382 00:17:15,626 --> 00:17:17,666 and now let's take a look at another program 383 00:17:21,416 --> 00:17:27,636 so here is style 2, let me just zoom 384 00:17:27,636 --> 00:17:29,006 out so you've got the full effect. 385 00:17:29,206 --> 00:17:31,666 >> Do we make the window bigger? 386 00:17:31,876 --> 00:17:36,096 >> So the appliance has a default size of 800 X 600 387 00:17:36,096 --> 00:17:37,406 and the projector is going to get kind 388 00:17:37,406 --> 00:17:38,516 of weird if we change that. 389 00:17:39,196 --> 00:17:42,946 So first we have this really long comment, 390 00:17:43,576 --> 00:17:47,166 so this is not uncommon for people to write us like an essay 391 00:17:47,166 --> 00:17:50,976 at the beginning of our code that says what it does. 392 00:17:50,976 --> 00:17:51,986 So feel free to read that. 393 00:17:52,336 --> 00:17:55,856 One other little thing is a little personal tick. 394 00:17:56,106 --> 00:17:59,256 Some people have three comments, three slashes instead 395 00:17:59,256 --> 00:18:00,386 of two slashes at the beginning. 396 00:18:00,386 --> 00:18:03,676 It's also good to have a space after those two slashes, 397 00:18:03,946 --> 00:18:07,616 so both of that is also in the style guide as well. 398 00:18:07,736 --> 00:18:08,486 so scroll down. 399 00:18:08,816 --> 00:18:11,986 So immediately what jumps out as you as bad style here? 400 00:18:12,366 --> 00:18:19,566 anybody? So first the curly braces, so they're kind 401 00:18:19,566 --> 00:18:20,546 of all over the place. 402 00:18:20,806 --> 00:18:24,466 So this one looks good but the other is on the same line. 403 00:18:24,646 --> 00:18:26,096 This curly brace is indented, 404 00:18:26,096 --> 00:18:27,496 this one I don't know what it's doing. 405 00:18:28,506 --> 00:18:30,456 So it makes a big difference, right? 406 00:18:30,456 --> 00:18:33,376 These two programs are functionally equivalent; 407 00:18:33,376 --> 00:18:34,736 they do the exact same thing. 408 00:18:35,076 --> 00:18:37,916 But their style is very, very different and it's pretty clear 409 00:18:37,916 --> 00:18:40,386 to see which is better than another. 410 00:18:40,966 --> 00:18:44,156 So you also notice that style we call this variable 411 00:18:44,156 --> 00:18:45,476 that we're getting from the user P 412 00:18:45,736 --> 00:18:48,526 and really we don't' know why we called it P, we just decided 413 00:18:48,526 --> 00:18:50,266 that letter was next to the brace. 414 00:18:51,166 --> 00:18:53,546 And there's no comments throughout this, 415 00:18:53,546 --> 00:18:56,306 so we don't really know what's going on unless you really think 416 00:18:56,306 --> 00:18:58,686 about it and then even then we don't really understand what was 417 00:18:58,686 --> 00:19:01,326 going through the programmers mind when they wrote it. 418 00:19:01,586 --> 00:19:03,616 So rather than this big, 500 word essay 419 00:19:03,616 --> 00:19:05,926 at the beginning it's good to just kind of pepper your code 420 00:19:05,926 --> 00:19:08,326 with comments, saying this is what this block of code does. 421 00:19:08,896 --> 00:19:11,826 Finally speaking of blocks of code, its' really good 422 00:19:11,826 --> 00:19:13,886 to hit return every once in a while 423 00:19:13,986 --> 00:19:15,396 to separate blocks of code. 424 00:19:15,696 --> 00:19:18,016 So this if and else, they're kind of related 425 00:19:18,016 --> 00:19:21,076 because the else replies to the if, but the score loop kind 426 00:19:21,076 --> 00:19:22,866 of really doesn't have much to do with that if else [inaudible] 427 00:19:22,896 --> 00:19:25,626 so I can have a carriage return here to kind 428 00:19:25,626 --> 00:19:27,716 of separate the loop out of the way. 429 00:19:29,096 --> 00:19:30,766 So other questions on code style? 430 00:19:31,196 --> 00:19:36,786 Excellent, so we'll all write beautifully indented code 431 00:19:36,786 --> 00:19:38,006 and make me very happy. 432 00:19:38,936 --> 00:19:43,496 Okay. So now let's actually start talking 433 00:19:43,496 --> 00:19:45,896 about the three programs that you have to write. 434 00:19:46,376 --> 00:19:50,186 So the first is called pennies, and pennies is inspired 435 00:19:50,186 --> 00:19:53,406 by the lecture example we saw, which is in a better idea 436 00:19:53,406 --> 00:19:57,106 to take 10 million dollars right away or get one penny 437 00:19:57,106 --> 00:19:59,216 in the first day of the month, double that on the second day 438 00:19:59,216 --> 00:20:01,776 of the month, again, and the answer 439 00:20:01,776 --> 00:20:02,956 of course, is the pennies. 440 00:20:03,756 --> 00:20:05,726 So what your program essentially needs 441 00:20:05,726 --> 00:20:11,156 to do is take some input first I want the number of days 442 00:20:11,156 --> 00:20:12,906 in the month, so that's just going 443 00:20:12,906 --> 00:20:14,696 to be what type of variable? 444 00:20:15,216 --> 00:20:19,276 And integer, exactly, we can't have fractional days 445 00:20:19,276 --> 00:20:22,736 in the month and there doesn't need to be two of the 34 days 446 00:20:22,736 --> 00:20:25,266 of the month, so that's just going to be an int. 447 00:20:25,896 --> 00:20:28,876 we need to spit out the number of pennies that I have 448 00:20:29,166 --> 00:20:31,856 at the end of the month, so as a second input we're going 449 00:20:31,856 --> 00:20:34,246 to say how many pennies do you start off with? 450 00:20:35,446 --> 00:20:38,416 So some example output of this program, so we are going 451 00:20:38,416 --> 00:20:41,736 to run pennies in the appliance because we've already written it 452 00:20:41,736 --> 00:20:43,776 and compiled it, and it's going to prompt 453 00:20:43,776 --> 00:20:45,186 for the number of days in the month. 454 00:20:45,566 --> 00:20:46,746 So notice on the example 455 00:20:46,746 --> 00:20:48,476 in the P side it actually prompts twice. 456 00:20:48,586 --> 00:20:50,786 And why does it prompt you again after the first one? 457 00:20:50,926 --> 00:20:52,926 >> [Inaudible] 458 00:20:53,066 --> 00:20:56,606 >> Exactly so 32, there's no month with 32 days yet. 459 00:20:56,606 --> 00:21:02,266 So after that it's going to ask you how many pennies do you have 460 00:21:02,266 --> 00:21:03,796 on the first day, and similarly 461 00:21:03,796 --> 00:21:06,116 if you said something stupid here you'd want 462 00:21:06,116 --> 00:21:06,976 to reprompt the user. 463 00:21:06,976 --> 00:21:10,126 And then finally it just spits out how many pennies you'd have 464 00:21:10,126 --> 00:21:14,716 if you doubled it every day for that month. 465 00:21:14,936 --> 00:21:18,416 So we need to get some input from the user, 466 00:21:18,586 --> 00:21:20,046 so we need to have this days and month 467 00:21:20,096 --> 00:21:21,916 and then allow the user to type that in. 468 00:21:21,916 --> 00:21:24,936 so the way to do that is with a combination of Print F 469 00:21:25,156 --> 00:21:27,776 which is going to display some message and Get Int 470 00:21:27,946 --> 00:21:30,866 which is this function that's defined in the CS50 library, 471 00:21:30,866 --> 00:21:34,346 that CS50 duck H and that's just going to allow you to read 472 00:21:34,526 --> 00:21:38,496 from the command line some value that happens to be an integer, 473 00:21:38,496 --> 00:21:41,726 so you can use it like intend equals Get Int, pretty simple. 474 00:21:42,966 --> 00:21:45,316 So just so you can see an example 475 00:21:45,316 --> 00:21:48,816 of how you'd use that let's open up 476 00:21:49,516 --> 00:21:58,456 [ background noise ] 477 00:21:58,956 --> 00:21:59,326 Yep, question? 478 00:21:59,326 --> 00:22:00,266 >> Can you slow down a bit? 479 00:22:00,266 --> 00:22:00,586 >> Oh, sure. 480 00:22:00,586 --> 00:22:01,196 I can slow down. 481 00:22:02,146 --> 00:22:05,336 So we are now getting input from the user, 482 00:22:05,336 --> 00:22:07,836 so we're using this function called Get Int. 483 00:22:07,836 --> 00:22:11,226 so here at the beginning we're including two things. 484 00:22:11,546 --> 00:22:13,796 The first is the CS50 library, 485 00:22:14,036 --> 00:22:16,476 so this is where Get Int is defined for us. 486 00:22:17,206 --> 00:22:19,776 The next is the standard IO library and this is 487 00:22:19,776 --> 00:22:21,836 where Print F is defined for us. 488 00:22:22,986 --> 00:22:24,496 >> Does the order matter? 489 00:22:25,126 --> 00:22:26,186 >> So does the order matter? 490 00:22:26,186 --> 00:22:29,516 In this case no because these files, they're not using any -- 491 00:22:29,516 --> 00:22:31,186 they're kind of mutually independent, 492 00:22:31,396 --> 00:22:33,076 so you can include them in either order. 493 00:22:33,076 --> 00:22:33,626 >> [Inaudible] 494 00:22:33,626 --> 00:22:34,726 >> What's that? 495 00:22:34,946 --> 00:22:40,276 So and sometimes in more complicated programs, 496 00:22:40,276 --> 00:22:45,216 like the order would matter, but it in this case it doesn't. 497 00:22:45,336 --> 00:22:46,676 So now the first thing we're going 498 00:22:46,676 --> 00:22:48,616 to do is Print F enter a number. 499 00:22:48,716 --> 00:22:50,716 So this is the equivalent of the days and month. 500 00:22:51,316 --> 00:22:54,696 Notice here that I did not include that forward slash end. 501 00:22:55,936 --> 00:23:00,066 Because I want by the spec what I want the input to look 502 00:23:00,066 --> 00:23:06,216 like is this, so that 32 shouldn't be on a new line, 503 00:23:06,216 --> 00:23:08,526 it should be on the same line as that message I printed. 504 00:23:08,886 --> 00:23:09,986 So I don't want to include 505 00:23:09,986 --> 00:23:14,276 that forward slash n. next we're going to get the integer 506 00:23:14,276 --> 00:23:16,356 from the user, so just like we saw in 10 equals [inaudible] 507 00:23:16,356 --> 00:23:18,986 and that's going to take care of a lot of user to type something 508 00:23:18,986 --> 00:23:20,376 and then reading what the user types 509 00:23:20,376 --> 00:23:21,676 and storing it into a variable. 510 00:23:22,846 --> 00:23:25,066 So now I have the value that the user typed 511 00:23:25,126 --> 00:23:26,996 in this variable called N. question? 512 00:23:27,356 --> 00:23:29,976 >> What if on the [inaudible]? 513 00:23:29,976 --> 00:23:31,656 >> Oh, so this -- this actually doesn't need 514 00:23:31,656 --> 00:23:33,676 to be here, that was just habit. 515 00:23:33,676 --> 00:23:36,506 So eventually we'll use those but for now like we sound 516 00:23:36,506 --> 00:23:39,596 like we can just say it main void. 517 00:23:40,116 --> 00:23:42,836 So those are basically arguments you can supply to the program 518 00:23:42,836 --> 00:23:45,956 so that you can tell the program some values at the beginning 519 00:23:45,956 --> 00:23:47,496 that you can use later, but we're not going 520 00:23:47,606 --> 00:23:50,676 to be using those in that PSET so we can just say it main void. 521 00:23:51,286 --> 00:23:53,836 So other questions? 522 00:23:55,006 --> 00:23:55,216 Yep? 523 00:23:55,216 --> 00:23:56,276 >> [Inaudible] is that D? 524 00:23:56,876 --> 00:24:01,156 >> Oh, yeah, I'll get to that right now. 525 00:24:01,746 --> 00:24:01,916 Yep? 526 00:24:01,916 --> 00:24:08,026 >> In the [inaudible] into RFC comma char star, [inaudible]? 527 00:24:08,026 --> 00:24:13,366 Is it under main? 528 00:24:13,366 --> 00:24:14,696 >> Yeah. So -- so I had 529 00:24:14,696 --> 00:24:17,156 that before this endear sea [inaudible] star [inaudible] 530 00:24:17,196 --> 00:24:20,306 thing, so that's we'll be using that in later pieces, 531 00:24:20,366 --> 00:24:22,716 but right now you can just say it main void. 532 00:24:22,716 --> 00:24:24,396 So that was by that. 533 00:24:24,396 --> 00:24:27,966 So now that we have the value, 534 00:24:27,966 --> 00:24:29,966 we want to display it to the user. 535 00:24:30,506 --> 00:24:33,846 So again were going to be using Print F, however, 536 00:24:33,846 --> 00:24:37,866 we can't just say your number was N because this is just going 537 00:24:37,866 --> 00:24:40,816 to print the letter N. instead we want 538 00:24:40,816 --> 00:24:44,266 to have some place holder that once Print F runs it's going 539 00:24:44,266 --> 00:24:46,166 to say okay, I have a place holder and I'm going 540 00:24:46,166 --> 00:24:49,076 to substitute this place holder with some value. 541 00:24:50,156 --> 00:24:52,746 so whoever made this decision, 542 00:24:52,746 --> 00:24:55,356 decides to percent D was a really good place holder 543 00:24:55,426 --> 00:24:56,156 for an integer. 544 00:24:56,566 --> 00:25:00,596 So this says when Print F runs my number was percent B is going 545 00:25:00,596 --> 00:25:02,586 to say okay I have some place holder I'm going 546 00:25:02,586 --> 00:25:05,696 to end a value to put in there. 547 00:25:05,696 --> 00:25:07,986 So to supply a value we're going to have a comma 548 00:25:08,256 --> 00:25:11,426 after our statement in quotes, and then we're going 549 00:25:11,426 --> 00:25:14,226 to have the variable that we want to substitute in there. 550 00:25:14,626 --> 00:25:17,876 So the D is for an integer, you can use F for a float, 551 00:25:17,996 --> 00:25:20,606 and so what this is going to do is say your number was 552 00:25:20,606 --> 00:25:24,306 and it's going to output the number at that you typed in. 553 00:25:25,286 --> 00:25:25,546 yeah? 554 00:25:26,126 --> 00:25:28,306 >> [Inaudible] percent and the [inaudible]? 555 00:25:29,806 --> 00:25:31,236 >> So should it be percent N? 556 00:25:31,486 --> 00:25:35,706 So no, so the D just means integer, so D for integer, 557 00:25:35,966 --> 00:25:37,116 if that helps you remember. 558 00:25:37,116 --> 00:25:44,206 So this just says that after this statement, there's going 559 00:25:44,206 --> 00:25:46,406 to be a comma, and there's going to be an integer. 560 00:25:46,606 --> 00:25:47,996 So if I wanted to say five here, 561 00:25:47,996 --> 00:25:48,696 and every time it would five here 562 00:25:48,696 --> 00:25:50,236 and every time it would say your number was five, 563 00:25:50,766 --> 00:25:52,546 then I could do that, but because I want it 564 00:25:52,546 --> 00:25:55,826 to be what the user typed in, I stored it in a variable, 565 00:25:55,916 --> 00:25:57,836 so now it's in memory floating around somewhere 566 00:25:58,036 --> 00:25:59,666 and I can say your number was 567 00:25:59,666 --> 00:26:01,626 and then whatever the user typed in. 568 00:26:01,626 --> 00:26:01,806 Yep? 569 00:26:02,366 --> 00:26:05,866 >> What's the difference between like you saying that [inaudible] 570 00:26:06,306 --> 00:26:08,366 versus what we can't have? 571 00:26:09,266 --> 00:26:11,736 >> So what's the difference between int and n equals Get Int 572 00:26:11,736 --> 00:26:12,806 and the standup thing? 573 00:26:13,086 --> 00:26:16,796 So Get Int actually just uses standup, this is just kind 574 00:26:16,796 --> 00:26:18,776 of a nicer way of looking at it. 575 00:26:18,776 --> 00:26:20,496 It also does a little bit of error checking for you, 576 00:26:20,496 --> 00:26:22,296 like if I type in a string then Get Int is going 577 00:26:22,296 --> 00:26:24,006 to say you didn't give me an integer, try again. 578 00:26:24,616 --> 00:26:27,006 So the Get Int is literally just a wrapper 579 00:26:27,096 --> 00:26:28,156 for that scan off thing. 580 00:26:29,586 --> 00:26:29,856 Yep? 581 00:26:30,156 --> 00:26:34,846 >> Do you capital the g in get and the in int? 582 00:26:34,846 --> 00:26:35,866 is it sensitive? 583 00:26:36,136 --> 00:26:38,496 >> So, yes, so I capitalize the g and the I 584 00:26:38,536 --> 00:26:39,926 because it is case sensitive. 585 00:26:40,166 --> 00:26:43,196 So these are functions, just like Print F is a function 586 00:26:43,196 --> 00:26:44,986 that someone else wrote for us and gave to us, 587 00:26:45,376 --> 00:26:47,736 Get Int s a function that someone else wrote and gave 588 00:26:47,736 --> 00:26:50,366 to us, and they happened to write it with a capital G 589 00:26:50,366 --> 00:26:53,346 and a capital I and so we have to use that capital g 590 00:26:53,346 --> 00:26:54,946 and the capital I else we'll get an error 591 00:26:54,946 --> 00:26:56,076 that says it doesn't exist. 592 00:26:56,956 --> 00:26:57,216 Yep? 593 00:26:57,456 --> 00:27:01,976 >> Do we need that Print F number was section, 594 00:27:02,156 --> 00:27:04,416 like in the example in the problem set 595 00:27:04,686 --> 00:27:10,296 like in the CS50 library there's like a sample program I guess 596 00:27:10,296 --> 00:27:13,596 that we can run and it doesn't spit out like your number -- 597 00:27:13,656 --> 00:27:16,896 like in that program you just type in enter a number you type 598 00:27:16,976 --> 00:27:19,736 in 5 for example and then it just puts 5 on the screen. 599 00:27:20,526 --> 00:27:21,166 Do you know what I mean? 600 00:27:21,166 --> 00:27:23,996 Like the second Print F that you put up there is not 601 00:27:24,166 --> 00:27:25,956 in the problem, is not in the program 602 00:27:26,126 --> 00:27:27,926 that you made in the problem set. 603 00:27:28,026 --> 00:27:28,416 >> So right. 604 00:27:28,416 --> 00:27:30,216 So the only -- we don't have to -- 605 00:27:30,216 --> 00:27:32,686 we don't have to display whatever number the user typed 606 00:27:32,686 --> 00:27:33,056 in, right? 607 00:27:33,316 --> 00:27:36,366 So if this Print F weren't here then it wouldn't 608 00:27:36,366 --> 00:27:37,076 output anything. 609 00:27:37,076 --> 00:27:39,046 It would just read an input and then it would just be done 610 00:27:39,046 --> 00:27:40,016 and you could do something else. 611 00:27:40,446 --> 00:27:42,986 >> Right. Like an optional [inaudible] include that or -- 612 00:27:43,636 --> 00:27:47,266 >> Yeah so in the example for the PSET you don't want to. 613 00:27:47,266 --> 00:27:49,136 You want to actually do something with the number 614 00:27:49,136 --> 00:27:50,416 and then output a different number. 615 00:27:50,926 --> 00:27:52,416 But in this case this is different, 616 00:27:52,416 --> 00:27:54,246 we're just outputting the number right away. 617 00:27:54,556 --> 00:27:56,516 So you probably wouldn't want to do this in the actual PSET 618 00:27:56,516 --> 00:27:59,196 but when you do want to output some number this is how you 619 00:27:59,196 --> 00:27:59,586 would do it. 620 00:27:59,656 --> 00:27:59,806 >> Right. 621 00:28:00,986 --> 00:28:01,206 >> Yep. 622 00:28:02,116 --> 00:28:11,446 >> Does the Get Int have to be directly 623 00:28:11,596 --> 00:28:15,756 after the Print F sequence or a little bit 624 00:28:15,756 --> 00:28:19,886 after we should have known what we were talking about. 625 00:28:19,886 --> 00:28:22,266 >> So does this have to go immediately 626 00:28:22,266 --> 00:28:24,276 after Print F statement? 627 00:28:24,276 --> 00:28:27,856 No, it doesn't if I didn't have this Print F here, 628 00:28:27,856 --> 00:28:32,786 what would happen when I run the program was it would just sit 629 00:28:32,786 --> 00:28:34,826 there and it would wait for input 630 00:28:34,826 --> 00:28:36,946 because we're saying get an integer. 631 00:28:37,176 --> 00:28:48,866 But as the user I'm kind of confused as to why it's waiting. 632 00:28:48,866 --> 00:28:51,776 I'm like well, maybe it's loading or something 633 00:28:51,776 --> 00:28:55,666 so we just want to display a message that says you need 634 00:28:55,666 --> 00:29:00,626 to enter a number and then the program is going 635 00:29:00,766 --> 00:29:05,016 to sit there and wait for it. 636 00:29:06,456 --> 00:29:10,056 So no, so you can really put the Get Int app 637 00:29:10,056 --> 00:29:12,706 to the Print F you can do some stuff after the Print F 638 00:29:12,706 --> 00:29:14,326 and then have the Get Int it's just kind 639 00:29:14,326 --> 00:29:15,596 of so the user knows what's going on. 640 00:29:15,596 --> 00:29:15,976 Yep? 641 00:29:16,136 --> 00:29:19,136 >> [inaudible] a long data set, what would the percent be? 642 00:29:19,176 --> 00:29:19,856 >> Oh, sure. 643 00:29:19,956 --> 00:29:24,946 so along is going to be ll, so percent ll. 644 00:29:24,946 --> 00:29:30,696 It's going to be along ,and then d for integer, f for float 645 00:29:30,696 --> 00:29:33,916 and that's all you'll need so far. 646 00:29:33,916 --> 00:29:35,096 So you can look that up I think 647 00:29:35,256 --> 00:29:38,146 in so Google is actually really, really helpful. 648 00:29:38,246 --> 00:29:40,796 If you have a problem goggling it, 649 00:29:40,796 --> 00:29:41,736 we'll find you the answer very quick. 650 00:29:41,766 --> 00:29:42,756 There's also a reference that CS50 has 651 00:29:42,786 --> 00:29:43,446 that basically has a list 652 00:29:43,476 --> 00:29:44,376 of every C function you'll ever need 653 00:29:44,406 --> 00:29:45,576 and it will show you what arguments it takes 654 00:29:45,606 --> 00:29:46,116 and how to use them. 655 00:29:46,146 --> 00:29:46,986 I can show you that like afterwards. 656 00:29:47,016 --> 00:29:47,406 All right so yep. 657 00:29:47,436 --> 00:29:48,156 >> [Inaudible] apps what your number was it 658 00:29:48,186 --> 00:29:48,876 in concerning the variable 659 00:29:48,906 --> 00:29:49,716 that it shows you just the number [inaudible]? 660 00:29:49,746 --> 00:29:50,916 >> Yes. So let's actually run this just to see. 661 00:29:50,946 --> 00:29:52,566 So I already compiled it so I can just say dot slash input. 662 00:29:52,596 --> 00:29:52,896 I hit enter. 663 00:29:52,926 --> 00:29:53,976 Oh, I have a random character, one second. 664 00:29:54,516 --> 00:30:07,966 [ background noise ] 665 00:30:08,466 --> 00:30:10,486 Okay. I decided like an extra something. 666 00:30:10,666 --> 00:30:14,346 Okay. So I'm going to say make input and I can run input. 667 00:30:14,346 --> 00:30:16,986 Now it's going to ask me to enter a number. 668 00:30:16,986 --> 00:30:19,926 I can say 5 and then it just says your number was 5. 669 00:30:20,106 --> 00:30:22,806 So where that percent d was was substituted with 5 670 00:30:22,896 --> 00:30:25,106 and I can say whatever I want there and it's going 671 00:30:25,106 --> 00:30:26,376 to spit back the number. 672 00:30:28,086 --> 00:30:28,356 Yep? 673 00:30:29,326 --> 00:30:30,886 >> Why do we need [inaudible]? 674 00:30:31,186 --> 00:30:32,156 >> So that's a good question. 675 00:30:32,156 --> 00:30:34,066 I think I just had a typo somewhere. 676 00:30:35,516 --> 00:30:42,576 [ background noise ] 677 00:30:43,076 --> 00:30:44,286 Yeah. There we go, so I just had a typo. 678 00:30:44,286 --> 00:30:46,596 So I just changed it back to void, saved it. 679 00:30:46,596 --> 00:30:53,586 I can say make input and it worked so I just typo somewhere. 680 00:30:53,586 --> 00:30:55,546 Okay. So let's move 681 00:30:55,546 --> 00:30:59,176 on to actually how we can implement this pennies program. 682 00:30:59,766 --> 00:31:04,776 So the first thing we want to make sure we do is 683 00:31:04,776 --> 00:31:06,576 to do something called input validation, 684 00:31:06,766 --> 00:31:08,276 to make sure what the user typed 685 00:31:08,276 --> 00:31:10,276 in is something we can actually use. 686 00:31:10,766 --> 00:31:12,796 So if I'm a grader and I decide that there are -- 687 00:31:12,796 --> 00:31:16,016 this is CS50 days in the month and I got negative pie pennies 688 00:31:16,016 --> 00:31:18,486 on the first day your program shouldn't blow up. 689 00:31:18,786 --> 00:31:20,226 It should let me know that ok you need 690 00:31:20,226 --> 00:31:22,966 to actually enter the right number of days and a number 691 00:31:22,966 --> 00:31:24,386 of pennies that actually make sense. 692 00:31:25,246 --> 00:31:27,046 So in this case you need to make sure that both 693 00:31:27,046 --> 00:31:30,136 of those inputs are numerical, which is something 694 00:31:30,136 --> 00:31:32,286 that Get Int is going to take care of for you, 695 00:31:32,626 --> 00:31:34,826 but what it's not going to do for you is make sure 696 00:31:34,826 --> 00:31:36,606 that the number of days in the month is valid. 697 00:31:37,046 --> 00:31:39,756 So if I say 100, your program needs to recognize 698 00:31:39,796 --> 00:31:42,236 that there aren't 100 days in the month and keep prompting me. 699 00:31:43,046 --> 00:31:46,056 And also, similarly the number of pennies has to make sense 700 00:31:46,186 --> 00:31:47,716 so if I say negative 100 pennies, 701 00:31:47,716 --> 00:31:50,416 your program shouldn't allow that to be an input. 702 00:31:50,556 --> 00:31:52,656 So what do you do? 703 00:31:52,656 --> 00:31:55,356 So let's say the I did say negative 100 pennies, 704 00:31:55,356 --> 00:31:57,036 how can you handle that in your coat? 705 00:31:57,926 --> 00:32:02,556 So we want to use some kind of loop that says keep prompting me 706 00:32:02,776 --> 00:32:05,216 until I give some valid input. 707 00:32:06,306 --> 00:32:08,426 So the first thing you want to do is to clear our variable, 708 00:32:08,806 --> 00:32:11,136 so it's we're going to store our input 709 00:32:11,136 --> 00:32:13,246 in something called n. let's just start it off 710 00:32:13,246 --> 00:32:14,826 at the number zero. 711 00:32:15,706 --> 00:32:18,776 So now I want you prompt for the input, 712 00:32:18,776 --> 00:32:21,146 so you're saying N equals Get Int and that's going 713 00:32:21,146 --> 00:32:24,026 to have the program wait for you to type something hit enter. 714 00:32:24,446 --> 00:32:26,856 And after you input that we're going to say okay, 715 00:32:27,396 --> 00:32:29,976 if it's not valid, then I want you to go back up to 716 00:32:29,976 --> 00:32:32,676 that n equals Get Int and do it again and I'm going 717 00:32:32,676 --> 00:32:35,036 to keep doing this until eventually n is valid 718 00:32:35,036 --> 00:32:37,346 and then I can get out of this loop. 719 00:32:37,736 --> 00:32:39,176 So this is a do while loop, 720 00:32:39,936 --> 00:32:43,636 so you'll notice this N equals Get Int is going to be executed 721 00:32:43,636 --> 00:32:46,686 for the first time regardless of what N is, so it's not going 722 00:32:46,686 --> 00:32:49,246 to check N and then ask you, it's going to ask you 723 00:32:49,426 --> 00:32:51,166 and then check what N is. 724 00:32:52,266 --> 00:32:53,776 so questions on what's going on here? 725 00:32:53,776 --> 00:32:53,926 Yep? 726 00:32:53,926 --> 00:32:58,086 >> Can you do it so that N is part of the [inaudible] 727 00:32:58,696 --> 00:33:02,346 >> So can I put the int N inside of the do, so no. 728 00:33:02,446 --> 00:33:05,156 and that's because of something called scope. 729 00:33:05,716 --> 00:33:09,196 So what scope is it limits where you can access a variable. 730 00:33:09,606 --> 00:33:12,146 So if I declare a variable inside of a loop, 731 00:33:12,146 --> 00:33:15,506 I can't get at that variable anymore once I leave that loop. 732 00:33:15,986 --> 00:33:19,856 So if I say int N equals Get Int, and then outside 733 00:33:19,856 --> 00:33:20,766 of the loop later, 734 00:33:21,056 --> 00:33:22,966 try to reference N it's going to be gone. 735 00:33:23,576 --> 00:33:26,786 So that's why outside of the loop we say int N equals zero, 736 00:33:26,786 --> 00:33:30,066 so this variable N is accessible everywhere outside of the loop, 737 00:33:30,696 --> 00:33:32,736 then we assign the value inside of the loop. 738 00:33:33,366 --> 00:33:33,566 Yep? 739 00:33:34,076 --> 00:33:35,956 >> So what is N stand for? 740 00:33:35,956 --> 00:33:37,896 >> So N just stands for number in this case just 741 00:33:37,896 --> 00:33:39,166 because it was shortened to fit on the slide. 742 00:33:39,166 --> 00:33:40,746 >> So the number where you put it in? 743 00:33:41,246 --> 00:33:43,916 >> Yeah. So that -- so N is the variable 744 00:33:44,286 --> 00:33:46,156 where your input is going to be stored. 745 00:33:46,456 --> 00:33:48,726 So if I said int pennies equals zero, 746 00:33:49,006 --> 00:33:50,396 then I would use pennies everywhere, 747 00:33:50,676 --> 00:33:53,886 and based on our style pennies would probably be a much better 748 00:33:53,886 --> 00:33:56,156 name than N but N just fits on the slide better. 749 00:33:57,176 --> 00:33:57,436 Yep? 750 00:33:57,436 --> 00:34:00,216 >> Is there a reason that you assign N when you do the loop 751 00:34:00,626 --> 00:34:02,986 and then you just normally sign up [inaudible] 752 00:34:02,986 --> 00:34:04,146 >> So is there a reason I assigned it? 753 00:34:04,146 --> 00:34:04,766 Not really, no. 754 00:34:04,766 --> 00:34:06,436 I could have just said indent semicolon. 755 00:34:06,636 --> 00:34:09,176 It's just once you're working with pointers and stuff, 756 00:34:09,176 --> 00:34:11,096 which is later, it's just good to assign things sometimes. 757 00:34:12,186 --> 00:34:13,106 Yep? Yep? 758 00:34:13,636 --> 00:34:14,376 >> Sorry. [inaudible] put the N 759 00:34:15,506 --> 00:34:20,106 in the loop could you put [inaudible] in [inaudible]? 760 00:34:21,096 --> 00:34:23,866 >> So could I put in int N equals Get Int 761 00:34:23,866 --> 00:34:25,696 on top of the loop? 762 00:34:25,696 --> 00:34:29,296 >> So I could and then say N equals Get Int inside 763 00:34:29,296 --> 00:34:30,286 of the loop but what that's going 764 00:34:30,286 --> 00:34:31,586 to do is it's going to prompt me twice. 765 00:34:32,016 --> 00:34:33,896 It's going to do the first Get Int then it's going to go 766 00:34:33,896 --> 00:34:35,256 into the loop and do another Get Int. 767 00:34:36,176 --> 00:34:38,416 so that's the reason that this is structured the way it is. 768 00:34:38,416 --> 00:34:38,606 Yep? 769 00:34:38,716 --> 00:34:42,316 >> So [inaudible] that every time you do the [inaudible] 770 00:34:42,316 --> 00:34:44,826 that you assign N? 771 00:34:45,126 --> 00:34:50,626 is there [inaudible] have to do that [inaudible] sometimes error 772 00:34:50,746 --> 00:34:54,226 to say that you assign the variable. 773 00:34:54,226 --> 00:34:57,116 >> So you're allowed to reassign multiple values to a variable, 774 00:34:57,116 --> 00:35:00,836 what you can't do is create two variables with the same name. 775 00:35:01,236 --> 00:35:04,286 so this int N is going to create a new variable called N. 776 00:35:04,686 --> 00:35:07,286 if I do int N somewhere else, it's going to yell at me 777 00:35:07,286 --> 00:35:09,356 because I already have a variable called N. 778 00:35:09,766 --> 00:35:12,856 so once it's created, you can assign to it whatever you want. 779 00:35:13,376 --> 00:35:15,576 But you can't -- what you can't do is create two different 780 00:35:15,576 --> 00:35:16,856 things and try to recreate it. 781 00:35:17,286 --> 00:35:21,986 Or else it's going to yell at you. 782 00:35:22,206 --> 00:35:24,156 Okay. So now that we have these -- Yep? 783 00:35:24,586 --> 00:35:28,946 >> How -- are you just -- did you define in that win 784 00:35:28,946 --> 00:35:30,646 and it's not valid ,or -- 785 00:35:30,646 --> 00:35:30,826 >> No, no. 786 00:35:30,826 --> 00:35:33,916 so this bottom while N is not valid, so that's not actual 787 00:35:33,916 --> 00:35:34,936 like see, you can type. 788 00:35:35,296 --> 00:35:37,666 You probably want to do something with like a greater 789 00:35:37,666 --> 00:35:39,986 than or an equal to or something like that, but -- 790 00:35:39,986 --> 00:35:44,536 >> So it's just like while N is less than or equal to. 791 00:35:44,966 --> 00:35:47,646 >> Yeah. Exactly so you could say like while N less than zero 792 00:35:47,646 --> 00:35:48,606 or lesser than equal to zero. 793 00:35:48,606 --> 00:35:51,656 So any booming expression, that thing you can see that evaluates 794 00:35:51,656 --> 00:35:54,876 to either true or false, based on the values you're giving it, 795 00:35:55,106 --> 00:35:57,176 that's where you'd want to put inside of this while here. 796 00:35:58,126 --> 00:35:58,366 Yep? 797 00:35:58,826 --> 00:36:01,086 >> So isn't that N equals [inaudible] 798 00:36:01,466 --> 00:36:04,526 because it's the silent [inaudible] 799 00:36:04,946 --> 00:36:08,046 or why did that [inaudible] 800 00:36:08,716 --> 00:36:10,686 >> So the reason it's not recreating the variable is 801 00:36:10,686 --> 00:36:12,526 because it's missing that int thing. 802 00:36:13,026 --> 00:36:15,956 So that int N is going to create the variable N. 803 00:36:16,836 --> 00:36:19,206 so if I'm just -- once it's created I can just use it 804 00:36:19,286 --> 00:36:20,106 by using its name. 805 00:36:21,296 --> 00:36:24,426 >> So if you're not declaring a variable then you don't 806 00:36:24,426 --> 00:36:27,826 interpret that as being you're using the variable. 807 00:36:27,826 --> 00:36:28,996 >> So say that again? 808 00:36:29,626 --> 00:36:33,236 >> So you're not declaring the type of the variable 809 00:36:33,806 --> 00:36:34,896 and [inaudible] will interpret 810 00:36:35,046 --> 00:36:36,906 that as being using the variable for -- 811 00:36:36,906 --> 00:36:37,886 >> Yes. Exactly. 812 00:36:37,886 --> 00:36:39,006 So if you don't give it a type -- 813 00:36:39,076 --> 00:36:41,626 so if I don't say int N I just say N then C is going 814 00:36:41,626 --> 00:36:42,726 to say I'm not creating it. 815 00:36:42,876 --> 00:36:43,996 It must exist somewhere. 816 00:36:43,996 --> 00:36:47,876 If it doesn't exist somewhere I'm going to yell at you. 817 00:36:48,416 --> 00:36:50,376 Okay. so once we have that input, 818 00:36:50,376 --> 00:36:53,186 let's go over what we want to do with it. 819 00:36:53,736 --> 00:36:55,566 So what we need to do is we want 820 00:36:55,566 --> 00:36:58,766 to keep doubling our money the right number of times, 821 00:36:58,856 --> 00:37:02,386 and then at the end output how much money we have. 822 00:37:03,596 --> 00:37:07,066 So this is some pseudo code, so not actual c code, 823 00:37:07,376 --> 00:37:10,496 but kind of code written out in English what you need to do. 824 00:37:11,076 --> 00:37:13,346 So lets' take a look at an outline of how we can do this. 825 00:37:13,666 --> 00:37:15,776 So the first thing we want to do is get the number of days 826 00:37:15,776 --> 00:37:18,186 in the month and after we get that we want to validate 827 00:37:18,186 --> 00:37:20,206 that input to make sure it's a number that makes sense 828 00:37:20,806 --> 00:37:22,396 and then we want to do the same for the number 829 00:37:22,396 --> 00:37:23,496 of pennies on the first day. 830 00:37:23,856 --> 00:37:25,636 Make sure that's a number of pennies that makes sense. 831 00:37:26,276 --> 00:37:28,106 So now we're going to enter our loop or the block 832 00:37:28,106 --> 00:37:29,856 of code that's going to repeat more than one time. 833 00:37:30,496 --> 00:37:32,486 So for every day after the first day, 834 00:37:32,686 --> 00:37:34,406 we're going to double the amount of pennies we have. 835 00:37:34,596 --> 00:37:36,516 And so that's going to represent the number of pennies 836 00:37:36,516 --> 00:37:37,776 that we get on that day. 837 00:37:38,206 --> 00:37:41,236 After that we want to update the total number of pennies we have. 838 00:37:42,296 --> 00:37:45,096 So after this loop is done, that means we've gotten some value 839 00:37:45,096 --> 00:37:46,626 from pennies for every day of the month 840 00:37:46,746 --> 00:37:49,056 and we can output the total number of dollars and cents 841 00:37:49,096 --> 00:37:50,806 that we have after the month is over. 842 00:37:52,196 --> 00:37:54,386 So this is essentially an outline for what you want 843 00:37:54,386 --> 00:37:57,266 to be writing and see, so you can't compile and run this, 844 00:37:57,366 --> 00:37:59,996 unfortunately, but you want to translate this just 845 00:37:59,996 --> 00:38:01,866 like we were going to translate scratch to see 846 00:38:02,056 --> 00:38:04,946 or to translate this pseudo code or like almost code, 847 00:38:04,946 --> 00:38:07,036 not quite, into actual code. 848 00:38:07,956 --> 00:38:10,856 So questions on this outline or what we went over so far? 849 00:38:11,436 --> 00:38:14,386 All right. 850 00:38:14,696 --> 00:38:15,816 So that's pennies. 851 00:38:16,576 --> 00:38:18,336 Let's move onto greeting. 852 00:38:19,186 --> 00:38:20,816 So this is, as the PSET says, 853 00:38:20,816 --> 00:38:23,056 an example of what greedy is going to look like. 854 00:38:23,606 --> 00:38:26,396 So after you write it and compile you can say greedy, 855 00:38:26,396 --> 00:38:29,076 it's going to ask you how much change is owed, 856 00:38:29,076 --> 00:38:30,706 and it's going to output a number. 857 00:38:30,706 --> 00:38:33,396 And that number is how to make that amount 858 00:38:33,396 --> 00:38:35,536 of change using the fewest coins possible. 859 00:38:36,676 --> 00:38:40,746 So the user inputted 41 in this case. 860 00:38:41,276 --> 00:38:44,846 Whoa. So let's look at how we'd make change for 41 cents. 861 00:38:45,526 --> 00:38:47,366 So the first thing we're going to do is use a quarter, 862 00:38:47,756 --> 00:38:49,956 so after our quarter we've used one coin 863 00:38:50,426 --> 00:38:52,796 and there's 16 cents left if I do the math right. 864 00:38:53,716 --> 00:38:55,526 So after that we can't use another quarter 865 00:38:55,526 --> 00:38:59,016 because then that's too much, so let's say okay let's use a dime. 866 00:38:59,356 --> 00:39:00,836 So now we've used two coins total, 867 00:39:00,836 --> 00:39:02,046 and there is six cents left. 868 00:39:03,026 --> 00:39:04,936 So now we can't use a dime because that's too big, 869 00:39:04,936 --> 00:39:05,706 so let's try a nickel. 870 00:39:06,486 --> 00:39:08,846 So now we've used three coins total, once step left, 871 00:39:09,156 --> 00:39:10,616 and finally we can just use a penny, 872 00:39:10,616 --> 00:39:12,886 so that means we've used four coins total 873 00:39:12,886 --> 00:39:14,826 and there's no change left so we're done. 874 00:39:15,066 --> 00:39:17,036 So that's where that four came from. 875 00:39:18,086 --> 00:39:20,486 So the reason we're doing things in that order is 876 00:39:20,486 --> 00:39:24,036 because our goal is to use the fewest amount of coins possible. 877 00:39:24,636 --> 00:39:27,316 So the strategy we're going to employ to do that is 878 00:39:27,316 --> 00:39:30,766 to use the best coin at each step. 879 00:39:31,436 --> 00:39:33,156 So at each step we have a different amount 880 00:39:33,156 --> 00:39:34,256 of change to make. 881 00:39:34,806 --> 00:39:38,006 So we just want to say make as much change as possible, 882 00:39:38,096 --> 00:39:40,246 so remove as much money as possible 883 00:39:40,246 --> 00:39:42,696 from what we owe you using as few coins as possible. 884 00:39:43,266 --> 00:39:46,946 So by using the biggest coin at each step, we're actually going 885 00:39:46,946 --> 00:39:50,866 to get the right answer, the fewest coins possible. 886 00:39:50,866 --> 00:39:54,196 So this isn't true for all problems and computer science, 887 00:39:54,196 --> 00:39:55,106 in fact it's usually not 888 00:39:55,106 --> 00:39:57,886 but in this case we can say just use the biggest coin possible 889 00:39:57,886 --> 00:40:00,876 and by doing that at every step we're going 890 00:40:00,876 --> 00:40:03,766 to get the right answer, the fewest coins possible overall. 891 00:40:03,766 --> 00:40:08,486 So we can do two things to accomplish this. 892 00:40:08,816 --> 00:40:11,036 The first is loose, you can kind 893 00:40:11,036 --> 00:40:12,376 of see how this is going to play out, right? 894 00:40:12,376 --> 00:40:15,076 We're going to try a quarter, keep using a quarter, 895 00:40:15,076 --> 00:40:16,276 till we can't use a quarter anymore. 896 00:40:16,276 --> 00:40:18,346 And then we're going to try to keep using a dime 897 00:40:18,406 --> 00:40:19,596 until we can't use a dime anymore. 898 00:40:20,176 --> 00:40:21,306 So that's one way to do it. 899 00:40:21,876 --> 00:40:24,356 Another way to do it is a more math way. 900 00:40:25,536 --> 00:40:29,106 So using division and something called the modulo operator, 901 00:40:29,886 --> 00:40:32,476 so what this operator is is basically a fancy way 902 00:40:32,476 --> 00:40:34,956 of saying get the remainder when I do some division. 903 00:40:35,726 --> 00:40:39,276 So if I had five modulo two, that's going 904 00:40:39,276 --> 00:40:42,286 to be what's the remainder when I do five divided by two. 905 00:40:43,146 --> 00:40:44,316 Which is one. 906 00:40:45,056 --> 00:40:48,336 so 11 mod three is going to be 2, because 11 divided 907 00:40:48,336 --> 00:40:51,706 by 3 would be 3 and then you have two left over, 908 00:40:51,706 --> 00:40:54,656 so that's two, and then if you're doing the modulo 909 00:40:54,656 --> 00:40:57,556 of something that's smaller, so if I do three modulo 4, 910 00:40:57,846 --> 00:41:00,206 3 is less than 4 so it's just going to be 3. 911 00:41:00,206 --> 00:41:02,686 So does that make sense to everyone what 912 00:41:02,686 --> 00:41:04,186 that percent sign thing is doing? 913 00:41:05,826 --> 00:41:08,196 >> I don't get why [inaudible] 914 00:41:08,426 --> 00:41:10,216 >> So yeah, so it's not quite divided by, 915 00:41:10,216 --> 00:41:11,346 so this is the remainder. 916 00:41:11,786 --> 00:41:13,876 So it's going to calculate 5 divided by 2, 917 00:41:14,136 --> 00:41:16,556 so this is going to be 2.5 right? 918 00:41:17,246 --> 00:41:20,186 So it's like 2 remainder 1, and so that's 919 00:41:20,186 --> 00:41:21,136 where that 1 came from. 920 00:41:21,676 --> 00:41:25,466 So same thing with 11 mod 3 and 3 mod 4. 921 00:41:26,996 --> 00:41:29,396 So combining this with division, 922 00:41:29,666 --> 00:41:32,956 we can actually calculate how much change is left 923 00:41:32,956 --> 00:41:36,776 after we use each coin, so if we divide our total by the value 924 00:41:36,776 --> 00:41:39,116 of the coin, then that's how many of that coin can be used, 925 00:41:39,116 --> 00:41:40,926 and then we can use the modulo to figure 926 00:41:40,926 --> 00:41:42,636 out how much change you need to make 927 00:41:42,776 --> 00:41:44,286 after using all those coins. 928 00:41:45,036 --> 00:41:48,046 So that's kind of the slightly fancier way of doing it, 929 00:41:49,116 --> 00:41:53,436 but before we can do that we need to convert our dollars 930 00:41:53,436 --> 00:41:55,246 and cents to just cents. 931 00:41:55,856 --> 00:41:57,496 So it's just easier to work with so we don't have 932 00:41:57,496 --> 00:41:58,366 to worry about decimals. 933 00:41:59,126 --> 00:42:02,676 So how do you learn to divert dollars to cents? 934 00:42:06,436 --> 00:42:08,366 So you just multiply by 100, right? 935 00:42:08,366 --> 00:42:10,666 So I have, you know, $1.25, 936 00:42:10,666 --> 00:42:12,776 I multiply by 100, I have 125 cents. 937 00:42:13,606 --> 00:42:20,326 So let's see what happens when we do that and see. 938 00:42:20,556 --> 00:42:27,556 So let's open up or let's write it. 939 00:42:28,316 --> 00:42:29,546 So let's create a new file. 940 00:42:30,086 --> 00:42:37,296 We're going to include our CS50.h, and we're going 941 00:42:37,296 --> 00:42:41,396 to include our standard IO.h, so just the two [inaudible] fails 942 00:42:41,646 --> 00:42:43,966 that allow us to get input from the user and pout something 943 00:42:43,966 --> 00:42:52,306 with Print F, so it's name void so now we want to get some value 944 00:42:52,306 --> 00:42:57,556 from the user, so I can say ent f equals get slope, 945 00:42:58,566 --> 00:43:02,006 and so just Get Int this is a function that someone else wrote 946 00:43:02,006 --> 00:43:04,896 for us, and it's going to get a decimal from the user. 947 00:43:05,426 --> 00:43:05,526 Yep? 948 00:43:05,526 --> 00:43:06,236 >> [Inaudible] 949 00:43:06,236 --> 00:43:06,826 >> Oh, yeah. 950 00:43:08,196 --> 00:43:10,846 Sorry. So that should be float f, 951 00:43:10,846 --> 00:43:16,736 not int f. So now once we have it, let's create some integer 952 00:43:16,736 --> 00:43:18,056 that represents the number of cents, 953 00:43:18,566 --> 00:43:21,386 so let's say int N equals F times 100. 954 00:43:22,676 --> 00:43:23,316 Makes sense, right? 955 00:43:23,316 --> 00:43:25,156 We're saying multiply it by 100 956 00:43:25,156 --> 00:43:27,206 and then we're going to have some cents. 957 00:43:27,206 --> 00:43:30,186 So now let's just print out what they have. 958 00:43:30,186 --> 00:43:32,496 So percent d because we're printing out an integer, 959 00:43:32,936 --> 00:43:35,236 and now comma, the value we want to print out, 960 00:43:35,436 --> 00:43:38,826 which is N. so does this make sense what's going on here? 961 00:43:38,826 --> 00:43:42,546 we're asking the user for some float, then we're going to take 962 00:43:42,546 --> 00:43:45,046 that float and we're going to multiply it by 100, 963 00:43:45,046 --> 00:43:47,166 so we have the number of cents that represents, 964 00:43:47,166 --> 00:43:50,436 and then we're just going to output the number of cents. 965 00:43:52,456 --> 00:43:57,656 So let's save this so I called it cents 966 00:43:57,696 --> 00:44:01,706 so let's say make cents all went well, 967 00:44:01,706 --> 00:44:04,266 no errors, now let's run cents. 968 00:44:05,556 --> 00:44:07,666 So you notice because I don't have a Print F anywhere, 969 00:44:07,666 --> 00:44:10,296 it's just sitting there waiting for me to enter something. 970 00:44:10,796 --> 00:44:16,426 So let's enter in that 0.41, hit enter and let's add a new line 971 00:44:16,426 --> 00:44:20,036 so you can see that better, so added a new line, I saved it, 972 00:44:20,036 --> 00:44:23,596 we're going to say make cents and try that again. 973 00:44:23,596 --> 00:44:27,906 So I'm going to say 0.41, 40 cents. 974 00:44:29,426 --> 00:44:29,976 Why would that happen? 975 00:44:30,516 --> 00:44:34,556 [ background noise ] 976 00:44:35,056 --> 00:44:37,486 So basically when we store something as a float and try 977 00:44:37,486 --> 00:44:39,326 to convert it to an int, we're going to do -- 978 00:44:39,326 --> 00:44:41,486 something's going to happen called a loss of precision. 979 00:44:42,066 --> 00:44:47,806 So C basically stores that .41 as maybe 0.409999 980 00:44:47,806 --> 00:44:48,876 or something like that. 981 00:44:48,876 --> 00:44:50,546 So when we convert to an integer, 982 00:44:50,676 --> 00:44:52,106 what she is doing is saying, okay, 983 00:44:52,106 --> 00:44:55,506 everything after the decimal point, just get rid of it. 984 00:44:55,636 --> 00:44:59,566 So if this was stored as 40.99999 and we get rid 985 00:44:59,566 --> 00:45:03,666 of everything after that decimal point, we're at 40, not 41. 986 00:45:04,416 --> 00:45:09,266 So what do we want to do instead? 987 00:45:09,266 --> 00:45:09,786 >> [Inaudible] around it. 988 00:45:09,786 --> 00:45:10,736 >> Right. We want a round. 989 00:45:11,126 --> 00:45:13,966 So luckily there's a function that someone else 990 00:45:14,046 --> 00:45:17,796 so nicely wrote for us called round. 991 00:45:18,346 --> 00:45:28,356 Oh, boy. So there's this function called round, 992 00:45:28,756 --> 00:45:31,346 and like Print F is defined in standard IO.h, 993 00:45:31,566 --> 00:45:34,956 this is defined in math.h. Yep? 994 00:45:35,266 --> 00:45:39,026 >> [inaudible] the functions are somehow like the round -- 995 00:45:39,026 --> 00:45:42,966 the round the [inaudible] there is a bunch of them [inaudible] 996 00:45:43,276 --> 00:45:44,156 >> Yes. So is there a list 997 00:45:44,156 --> 00:45:45,656 of some functions on line somewhere? 998 00:45:45,706 --> 00:45:49,006 There is so there's a good list called CPP reference.com, 999 00:45:49,266 --> 00:45:52,506 but if you just Google like list of math.h functions or even just 1000 00:45:52,506 --> 00:45:55,636 like list of C standard library functions or something, 1001 00:45:55,636 --> 00:45:56,326 you'll find something. 1002 00:45:56,986 --> 00:45:58,586 I 'little try to find a good link right 1003 00:45:58,586 --> 00:45:59,786 after this and show everybody. 1004 00:46:00,406 --> 00:46:03,626 So questions on round? 1005 00:46:03,866 --> 00:46:07,206 So to use it, we just want to say instead 1006 00:46:07,206 --> 00:46:09,966 of int N equals F times 100, we just want 1007 00:46:09,966 --> 00:46:13,376 to say round, F times 100. 1008 00:46:14,006 --> 00:46:17,616 And so this round is going to return a rounded value. 1009 00:46:17,786 --> 00:46:19,726 so just like we said int N equals Get Int, 1010 00:46:19,726 --> 00:46:21,726 we're going to say int N equals round, 1011 00:46:22,266 --> 00:46:25,376 the value that we take in, times 100 to make it to cents, 1012 00:46:26,126 --> 00:46:27,296 and rounded correctly. 1013 00:46:27,506 --> 00:46:28,626 So we don't just truncate. 1014 00:46:29,726 --> 00:46:34,436 Now if we save this we're going to say make sense. 1015 00:46:35,686 --> 00:46:36,336 So just Yep? 1016 00:46:37,586 --> 00:46:39,996 >> Based on the [inaudible] 1017 00:46:39,996 --> 00:46:42,156 >> So yes, I was about to get an error, so I also have 1018 00:46:42,156 --> 00:46:48,056 to say include math.h. so just as a reminder, 1019 00:46:48,056 --> 00:46:49,656 every time you change your program, 1020 00:46:49,656 --> 00:46:51,246 you can't just run it again. 1021 00:46:51,386 --> 00:46:52,936 So I can't just say .cents again 1022 00:46:52,936 --> 00:46:54,236 because I was still going to get that error. 1023 00:46:54,666 --> 00:46:56,836 So every time you make a change make sure you save it, 1024 00:46:57,186 --> 00:47:00,596 then make sure you say make and then the name of your program 1025 00:47:00,656 --> 00:47:04,166 without the .c so I said, make sense and I'm going 1026 00:47:04,166 --> 00:47:08,656 to run cents again, 0.41. 1027 00:47:09,586 --> 00:47:12,806 so now we are good to go, we're not going to be off by one. 1028 00:47:14,106 --> 00:47:17,226 so questions on why we need round or how round works? 1029 00:47:17,746 --> 00:47:17,846 Yep? 1030 00:47:19,016 --> 00:47:25,856 >> Why didn't we have to like say need to [inaudible]? 1031 00:47:26,076 --> 00:47:28,176 Its figures [inaudible]? 1032 00:47:28,246 --> 00:47:30,496 >> So how do we say we didn't need two significant figures? 1033 00:47:30,496 --> 00:47:34,646 >> We do need -- like here we do need two significant figures, 1034 00:47:34,726 --> 00:47:37,276 [inaudible] understand that we do need two figures. 1035 00:47:37,526 --> 00:47:38,826 >> So no, it doesn't. 1036 00:47:38,826 --> 00:47:42,796 so if -- if I typed in like 0.413 we're just going 1037 00:47:42,796 --> 00:47:44,276 to chop off that 3 at the end. 1038 00:47:44,996 --> 00:47:47,016 Because if I just said 0.4 that's going 1039 00:47:47,016 --> 00:47:48,686 to be interpreted as 0.40. 1040 00:47:49,566 --> 00:47:52,106 so we can, you know, we're not going to deal with halves 1041 00:47:52,106 --> 00:47:53,426 of cents or anything, we'll just deal 1042 00:47:53,466 --> 00:47:55,026 with at least pennies as the lowest. 1043 00:47:55,276 --> 00:47:55,456 Yep? 1044 00:47:55,796 --> 00:48:00,286 >> [Inaudible] section of the [inaudible] is using this round, 1045 00:48:01,686 --> 00:48:03,816 is using round a good idea to get -- 1046 00:48:04,686 --> 00:48:07,366 to get the decimal place correct 1047 00:48:07,596 --> 00:48:10,996 when you print off the money at the end? 1048 00:48:11,076 --> 00:48:12,706 >> So yeah, so you might want to do that. 1049 00:48:12,706 --> 00:48:15,446 I think the problem set specifies if you should round 1050 00:48:15,446 --> 00:48:18,326 or just truncate, so whichever the problem set says, 1051 00:48:18,636 --> 00:48:22,466 I'm not sure off the top of my head. 1052 00:48:22,826 --> 00:48:22,916 Yep? 1053 00:48:22,916 --> 00:48:27,386 >> So like you want to round numbers, you're like more, 1054 00:48:27,416 --> 00:48:28,976 so the reading in some places, 1055 00:48:29,186 --> 00:48:31,946 how would you discuss the fact that that happened? 1056 00:48:32,546 --> 00:48:34,196 >> So if you wanted to round to -- 1057 00:48:34,366 --> 00:48:36,256 so in this case we're dealing, 1058 00:48:36,256 --> 00:48:37,476 we're just dealing with integers. 1059 00:48:37,766 --> 00:48:40,956 >> Right. So let's say you have like a full and you want 1060 00:48:40,956 --> 00:48:45,226 to like round it up to like 3 or something. 1061 00:48:45,906 --> 00:48:48,646 >> So yes, so you definitely won't have to do 1062 00:48:48,646 --> 00:48:50,706 that in this problem set, but usually what you'd want 1063 00:48:50,706 --> 00:48:52,346 to do is just kind of deal with the number 1064 00:48:52,346 --> 00:48:54,056 in as many decimal places as possible 1065 00:48:54,056 --> 00:48:56,656 and then once you're done with it you can truncate. 1066 00:48:57,286 --> 00:48:57,506 >> Okay. 1067 00:48:57,946 --> 00:49:00,406 >> So there's a way in Print F to just display 1068 00:49:00,406 --> 00:49:02,046 like two totally different decimal places. 1069 00:49:02,386 --> 00:49:07,436 But yeah, so the best thing to do is just deal 1070 00:49:07,436 --> 00:49:09,006 with as many decimal places as possible, 1071 00:49:09,006 --> 00:49:14,096 and then once you're done, out the rate on the ops. 1072 00:49:15,326 --> 00:49:18,396 >> So now let's go through the outline for greedy.c. 1073 00:49:18,776 --> 00:49:20,446 so again we want to do user input 1074 00:49:20,446 --> 00:49:22,996 to make sure they typed something that we can use, 1075 00:49:23,626 --> 00:49:25,306 and I want to keep track of two things, 1076 00:49:25,696 --> 00:49:29,826 the first being how many coins you use in total, so a counter 1077 00:49:29,826 --> 00:49:30,776 of how many coins you've used. 1078 00:49:30,776 --> 00:49:34,056 And then how much change is left to you in any given step. 1079 00:49:34,456 --> 00:49:36,006 So we want to know, yeah, I used two coins, 1080 00:49:36,226 --> 00:49:37,396 how much change do I have left? 1081 00:49:38,496 --> 00:49:40,346 So when we're using these coins we want to try 1082 00:49:40,346 --> 00:49:42,986 to use each coin, in descending order. 1083 00:49:43,676 --> 00:49:46,836 So quarters first, dimes, nickels, pennies. 1084 00:49:46,836 --> 00:49:49,146 So then we're going to do this until there's no change left, 1085 00:49:49,706 --> 00:49:51,756 and then we get output the number of coins, 1086 00:49:52,056 --> 00:49:53,836 so make sure you're not outputting zero every time 1087 00:49:53,836 --> 00:49:56,196 because the zero change left, but output the number 1088 00:49:56,196 --> 00:49:57,436 of coins that were used. 1089 00:49:58,276 --> 00:50:00,856 And so here's the pseudo code outline. 1090 00:50:01,456 --> 00:50:03,156 again this is just one way to do it. 1091 00:50:03,156 --> 00:50:05,396 This doesn't use that division or modulus operator, 1092 00:50:05,596 --> 00:50:07,236 but this is using the loops approach. 1093 00:50:07,916 --> 00:50:09,876 So you're going to get the money you want to make change for, 1094 00:50:10,816 --> 00:50:13,836 convert that into cents, now we're going to say wow, 1095 00:50:13,836 --> 00:50:14,856 there is more than a quarter left, 1096 00:50:15,716 --> 00:50:17,166 then I want to subtract a quarter 1097 00:50:17,166 --> 00:50:18,476 from how much change we're making, 1098 00:50:18,476 --> 00:50:20,006 and then you say I just used a coin. 1099 00:50:20,006 --> 00:50:22,766 So we're going to do that until there's no more 1100 00:50:22,766 --> 00:50:24,936 than a quarter left, then we can say okay. 1101 00:50:25,076 --> 00:50:26,246 well there's more than a dime left, 1102 00:50:26,246 --> 00:50:28,866 I'm going to take a dime off how much money I'm making change 1103 00:50:28,866 --> 00:50:30,806 for, and then I just use another coin. 1104 00:50:31,246 --> 00:50:32,666 So make that counter go up by one. 1105 00:50:33,336 --> 00:50:34,166 then once that's all done, 1106 00:50:34,166 --> 00:50:36,516 I'm going to say this is how many coins I used. 1107 00:50:36,826 --> 00:50:38,176 And if your counter's working right then 1108 00:50:38,176 --> 00:50:41,526 that counter should be exactly how many coins are necessary 1109 00:50:41,526 --> 00:50:43,296 to make that much change. 1110 00:50:44,556 --> 00:50:46,496 So questions on that outline? 1111 00:50:47,066 --> 00:50:51,606 >> What is the [inaudible] again? 1112 00:50:51,776 --> 00:50:53,216 >> So that increment coins used, 1113 00:50:53,216 --> 00:50:55,026 so you want to be having some counter 1114 00:50:55,026 --> 00:50:57,176 of how many coins have been used so far, and you just want 1115 00:50:57,176 --> 00:50:58,606 to make that kind of go up by one 1116 00:50:59,526 --> 00:51:00,736 because you just use one coin. 1117 00:51:01,166 --> 00:51:01,256 Yep? 1118 00:51:01,476 --> 00:51:04,186 >> So you set up the counter and you read it to all 1119 00:51:04,186 --> 00:51:08,096 of them [inaudible] costs when you [inaudible]? 1120 00:51:08,096 --> 00:51:12,006 >> Yeah. So we would probably want to use an integer 1121 00:51:12,006 --> 00:51:13,436 for this counter, because you're never going 1122 00:51:13,436 --> 00:51:14,416 to be using half a coin. 1123 00:51:14,796 --> 00:51:17,176 And then just make that integer go up every time you use a coin. 1124 00:51:18,446 --> 00:51:18,666 Yep? 1125 00:51:19,316 --> 00:51:21,416 >> Are we assuming that we're only making change 1126 00:51:21,836 --> 00:51:25,696 for quarters and smaller amounts? 1127 00:51:25,696 --> 00:51:28,006 >> Yes. I think the quarter is the biggest you can use. 1128 00:51:28,006 --> 00:51:28,716 It's in the problem set, 1129 00:51:28,716 --> 00:51:30,666 like what the highest coin you can use is, 1130 00:51:30,666 --> 00:51:31,506 but it should be a quarter. 1131 00:51:31,506 --> 00:51:39,216 All right, so one program left, and that is chart. 1132 00:51:39,466 --> 00:51:40,336 Oops, a question before that? 1133 00:51:40,796 --> 00:51:46,036 >> Yeah. If you have [inaudible] and then an [inaudible]? 1134 00:51:46,596 --> 00:51:48,336 >> Sure. so you know, there is more 1135 00:51:48,336 --> 00:51:49,316 than one thing you can do here. 1136 00:51:49,316 --> 00:51:51,136 you can use one Y loop and a bunch of [inaudible] 1137 00:51:51,136 --> 00:51:53,406 and you can use no loops at all and still do it. 1138 00:51:53,696 --> 00:51:55,046 There's a bunch of different ways 1139 00:51:55,046 --> 00:51:57,886 that you could write this program. 1140 00:51:58,356 --> 00:51:59,836 so where one is better than the other is 1141 00:51:59,836 --> 00:52:00,936 where a design comes into play. 1142 00:52:01,266 --> 00:52:02,606 So after you write your program you can think 1143 00:52:02,606 --> 00:52:04,066 to yourself can I do this better? 1144 00:52:04,556 --> 00:52:06,636 Like does this look kind of ugly or is this kind 1145 00:52:06,636 --> 00:52:08,486 of a dumb thing I did her or can I do this better? 1146 00:52:08,886 --> 00:52:10,826 And once the answer to that question is no, 1147 00:52:11,106 --> 00:52:12,886 then you should probably submit your PSET, 1148 00:52:13,436 --> 00:52:15,706 or if it's the deadline that's a good time to submit it too. 1149 00:52:17,676 --> 00:52:20,016 So other questions on greedy? 1150 00:52:20,536 --> 00:52:25,996 Okay. so last program is chart, and so this we're going 1151 00:52:25,996 --> 00:52:29,066 to be implementing our bar graph library, it's going to be sweet. 1152 00:52:29,286 --> 00:52:32,226 So we're going to ask the user for four different numbers, 1153 00:52:32,656 --> 00:52:34,446 number of males spotting females, 1154 00:52:34,446 --> 00:52:36,186 females spotting males, and so on. 1155 00:52:36,866 --> 00:52:39,186 And so after we get all those values we want 1156 00:52:39,186 --> 00:52:43,086 to somehow display a bar graph so we can visualize, you know, 1157 00:52:43,086 --> 00:52:45,586 who what gender is spotting the other gender the most 1158 00:52:45,586 --> 00:52:46,096 or the least. 1159 00:52:46,666 --> 00:52:51,776 So the maximum width of this chart is going 1160 00:52:51,776 --> 00:52:52,936 to be 80 characters. 1161 00:52:54,236 --> 00:52:55,326 So that means that there can be 1162 00:52:55,326 --> 00:52:59,686 at most 80 hash tags across the screen. 1163 00:52:59,876 --> 00:53:03,066 So you'll notice that there were three males spotting females, 1164 00:53:03,346 --> 00:53:05,266 but there aren't three hash tags. 1165 00:53:05,606 --> 00:53:07,506 That's because this is based on proportion. 1166 00:53:08,146 --> 00:53:12,006 So what percentage of the total spotting were male 1167 00:53:12,006 --> 00:53:12,836 spotting females? 1168 00:53:12,836 --> 00:53:16,106 And that is how we determine the width of that bar. 1169 00:53:16,316 --> 00:53:19,136 So let's take a look at this example. 1170 00:53:19,136 --> 00:53:23,306 So there were 3, 4, 1 and 2 in that order, and so that's going 1171 00:53:23,306 --> 00:53:25,276 to add up to 10 total sites. 1172 00:53:26,086 --> 00:53:30,306 So that means that 30 percent were males spotting females, 1173 00:53:30,426 --> 00:53:33,186 40 percent were females spotting males, and so on. 1174 00:53:34,086 --> 00:53:37,066 So now you have everything as a percentage and you want 1175 00:53:37,066 --> 00:53:39,916 to convert that percentage to those hash tags, 1176 00:53:39,916 --> 00:53:42,656 because 30 percent doesn't mean 30 hashes either. 1177 00:53:43,226 --> 00:53:46,176 So to do that, we're going to say okay, I have 30 percent, 1178 00:53:46,466 --> 00:53:47,656 what's 30 percent of 80? 1179 00:53:48,066 --> 00:53:49,626 And I'm going to get some number. 1180 00:53:50,476 --> 00:53:53,686 So the problem set specifies if I get a number and it's a -- 1181 00:53:53,686 --> 00:53:57,626 you know, 24.1, I'm just going to always round down. 1182 00:53:57,626 --> 00:53:59,496 So just get rid of the decimal place, 1183 00:54:00,096 --> 00:54:01,556 don't worry about rounding up correctly, 1184 00:54:01,556 --> 00:54:03,966 just always round down. 1185 00:54:03,966 --> 00:54:08,756 So I have 24 of these, 32 female spotting males, and so on, 1186 00:54:09,456 --> 00:54:12,116 and so now you'll notice there are 8 females spotting females 1187 00:54:12,116 --> 00:54:15,016 and so we have 8 hash tags at the bottom there. 1188 00:54:16,186 --> 00:54:21,596 So questions on the behavior of what this is supposed to do? 1189 00:54:21,816 --> 00:54:21,946 Yep? 1190 00:54:22,286 --> 00:54:25,486 >> If we're always rounding down, did the -- 1191 00:54:25,486 --> 00:54:28,926 like do the [inaudible] have to add up to 80 in the end? 1192 00:54:28,926 --> 00:54:30,836 >> So do they have to add up to 80 in the end? 1193 00:54:30,836 --> 00:54:33,116 No, because you know, you'll run into rounding errors. 1194 00:54:33,306 --> 00:54:35,106 So they don't have to add up to 80, 1195 00:54:35,186 --> 00:54:38,286 but the rule is get the percentage and get that basic, 1196 00:54:38,346 --> 00:54:40,406 get that percentage of 80 and then round down. 1197 00:54:40,816 --> 00:54:42,236 So they won't necessarily all add 1198 00:54:42,236 --> 00:54:43,726 up to 80 every time I don't think. 1199 00:54:44,876 --> 00:54:45,236 Maybe they do. 1200 00:54:45,936 --> 00:54:46,176 Yep? 1201 00:54:46,546 --> 00:54:49,966 >> So the [inaudible] function will let you decide whether 1202 00:54:49,966 --> 00:54:52,726 you're going to round up or down or -- 1203 00:54:52,816 --> 00:54:54,846 >> So that round function we looked at is going 1204 00:54:54,846 --> 00:54:56,556 to round correctly either way. 1205 00:54:57,566 --> 00:54:58,926 So we don't want to round correctly, 1206 00:54:58,926 --> 00:55:00,216 we just want to round down. 1207 00:55:00,716 --> 00:55:04,016 So that essentially means is just chop off all the decimals 1208 00:55:04,416 --> 00:55:06,566 after the float or whatever it is that we're using. 1209 00:55:07,316 --> 00:55:09,886 So what that is is what we actually tried the first time, 1210 00:55:10,016 --> 00:55:11,726 we tried to convert cents to dollars, 1211 00:55:11,796 --> 00:55:14,486 we effectively just chopped off all those decimal places 1212 00:55:14,856 --> 00:55:17,816 which in that problem was wrong, but in this problem is right. 1213 00:55:17,816 --> 00:55:21,206 >> Why do we need to round down? 1214 00:55:21,206 --> 00:55:22,386 >> So why do we want to round down? 1215 00:55:22,386 --> 00:55:24,526 Just because the PSET said so, it's slightly easier, 1216 00:55:25,356 --> 00:55:27,236 so we don't ever run into 81 sometimes. 1217 00:55:27,756 --> 00:55:27,916 Yep? 1218 00:55:28,426 --> 00:55:30,116 >> Can you repeat why the -- 1219 00:55:31,046 --> 00:55:33,066 why it chops off all the [inaudible]? 1220 00:55:36,576 --> 00:55:38,946 >> So why it chopped off the decimal place, sure. 1221 00:55:38,946 --> 00:55:42,726 so if I have a float and I want to convert that float to an int, 1222 00:55:43,236 --> 00:55:46,036 the way that C is going to do that , is it's going to say, 1223 00:55:46,036 --> 00:55:47,626 well, there's an integer at the beginning 1224 00:55:47,626 --> 00:55:49,056 of my float, let's just use that. 1225 00:55:49,646 --> 00:55:50,936 So that's just something that C does. 1226 00:55:51,026 --> 00:55:53,506 C isn't smart enough to round for you, it just assumes 1227 00:55:53,506 --> 00:55:55,816 that you want to effectively round down or get rid 1228 00:55:55,816 --> 00:55:56,796 of all the decimal places. 1229 00:55:58,006 --> 00:56:02,476 So if I say like int N equals get float, I'm just going to get 1230 00:56:02,716 --> 00:56:03,916 that float rounded down. 1231 00:56:04,266 --> 00:56:08,576 >> But in the case of the point 41, it just rounds 1232 00:56:08,666 --> 00:56:11,016 down to the [inaudible] that's zero? 1233 00:56:11,786 --> 00:56:12,806 >> Right. And so this is -- 1234 00:56:12,806 --> 00:56:14,876 has to do with how floats are stored. 1235 00:56:15,226 --> 00:56:22,526 So we're not actually storing 0.41, we're storing 0.40999999 1236 00:56:22,526 --> 00:56:24,456 or something, and so basically when we're going 1237 00:56:24,456 --> 00:56:27,136 to chop off we're going to lose all those 9s. 1238 00:56:27,136 --> 00:56:29,106 so that Y isn't so important right now, but it's more 1239 00:56:29,106 --> 00:56:31,516 of just make sure that you use round on that part, 1240 00:56:31,756 --> 00:56:33,996 but on this part we can just chop off. 1241 00:56:34,186 --> 00:56:34,286 Yep? 1242 00:56:35,966 --> 00:56:41,026 >> I don't understand the problem you're trying to solve. 1243 00:56:41,026 --> 00:56:42,116 I thought you were trying 1244 00:56:42,116 --> 00:56:45,986 to solve the first one you showed us, 1245 00:56:46,576 --> 00:56:49,176 but I don't understand what I'm trying to solve here. 1246 00:56:49,676 --> 00:56:50,466 >> So the chart itself? 1247 00:56:50,466 --> 00:56:50,536 >> Yeah. 1248 00:56:50,536 --> 00:56:51,916 >> So what we want to do is we want 1249 00:56:51,916 --> 00:56:54,626 to say I saw this many people 1250 00:56:54,626 --> 00:56:56,476 of each gender spotting some gender, 1251 00:56:56,996 --> 00:57:01,976 and I want to output a bar graph that visualizes what those -- 1252 00:57:01,976 --> 00:57:05,296 what those values are as a percentage of all the sittings. 1253 00:57:06,076 --> 00:57:08,366 So there were, you know, 10 sittings total, 1254 00:57:08,946 --> 00:57:12,246 of those 30 percent of them were males spotting females, 1255 00:57:12,636 --> 00:57:16,496 and so this bar is 30 percent of the maximum possible width. 1256 00:57:16,876 --> 00:57:18,886 Does that make sense? 1257 00:57:19,046 --> 00:57:20,556 >> Do you take individual representation? 1258 00:57:21,056 --> 00:57:22,676 >> Yes. So you're basically taking these numbers 1259 00:57:22,676 --> 00:57:24,426 and making a bar graph in text 1260 00:57:24,756 --> 00:57:27,036 so visualizing what those look like. 1261 00:57:28,066 --> 00:57:30,166 >> So you're given those numbers? 1262 00:57:30,166 --> 00:57:32,816 >> So these numbers you're going to prompt the user for them. 1263 00:57:33,056 --> 00:57:36,166 so the user's going to type in 3 or whatever they want, 1264 00:57:36,566 --> 00:57:38,226 and then based on what the user types in, 1265 00:57:38,226 --> 00:57:39,486 you want to display a different graph. 1266 00:57:40,086 --> 00:57:40,186 Yep? 1267 00:57:42,196 --> 00:57:47,366 >> And how do you get the program to put out the number 1268 00:57:47,366 --> 00:57:51,316 of hash marks that you want? 1269 00:57:51,556 --> 00:57:53,666 >> So a good question. 1270 00:57:53,866 --> 00:57:57,276 So we probably want to use some kind of loop, right? 1271 00:57:58,136 --> 00:58:01,106 So here's this quick pseudo code English outline. 1272 00:58:01,436 --> 00:58:03,246 we want to get those four values, 1273 00:58:03,676 --> 00:58:04,866 make sure that they're integers, 1274 00:58:04,866 --> 00:58:06,256 because you can have fractional people. 1275 00:58:06,256 --> 00:58:09,236 and we want to calcite the total number, 1276 00:58:09,556 --> 00:58:11,296 so just like we did before, we added them all 1277 00:58:11,296 --> 00:58:13,396 up to get the total number, and now we want 1278 00:58:13,396 --> 00:58:15,326 to convert those to percentages. 1279 00:58:16,436 --> 00:58:19,206 And based on those percentages, you want to get a number 1280 00:58:19,206 --> 00:58:22,286 of hash tags to display. 1281 00:58:22,456 --> 00:58:24,596 Now based on that number, you want to print 1282 00:58:24,596 --> 00:58:27,806 out that many hash tags, so if I got a 10, 1283 00:58:27,806 --> 00:58:31,676 I want to have some loop that prints out 10 hash tags. 1284 00:58:32,326 --> 00:58:35,946 So if inside of my loop we have our Print F and we don't include 1285 00:58:35,946 --> 00:58:39,766 that forward slash N, then it's going to stay on the same line. 1286 00:58:39,766 --> 00:58:41,156 So you're basically going to print 1287 00:58:41,156 --> 00:58:42,726 out everything line by line. 1288 00:58:42,726 --> 00:58:45,796 So we're going to say I'm not the male-spotting female track, 1289 00:58:45,796 --> 00:58:48,316 so I'm going to print out all the hash tags based 1290 00:58:48,316 --> 00:58:49,896 on how many we calculate it to be. 1291 00:58:50,576 --> 00:58:53,336 So we calculated there to be 10 so I want 10 hash tags 1292 00:58:53,526 --> 00:58:55,526 and then I want a new line because then I want 1293 00:58:55,526 --> 00:58:57,826 to say female spotting male on a new line, 1294 00:58:58,666 --> 00:59:02,466 and then another graph. 1295 00:59:03,186 --> 00:59:07,596 Does that make sense? 1296 00:59:07,826 --> 00:59:07,896 >> Yeah. 1297 00:59:08,736 --> 00:59:12,806 >> Okay. so just again, so after we do all 1298 00:59:12,806 --> 00:59:14,756 of our math we're going to get some values. 1299 00:59:14,756 --> 00:59:18,926 We're going to say, okay, I want 24 hash for male, the first one, 1300 00:59:19,006 --> 00:59:22,616 32 for the second one, and so now we want to have loops 1301 00:59:22,926 --> 00:59:24,666 that display each of those. 1302 00:59:25,306 --> 00:59:27,896 So we know that we want 24, so we want some loop 1303 00:59:28,056 --> 00:59:32,326 that executes 24 times that just prints a single hash. 1304 00:59:32,906 --> 00:59:35,276 So if you have a loop that executes 24 times and each 1305 00:59:35,276 --> 00:59:37,416 of those 24 times it prints a single hash, 1306 00:59:37,626 --> 00:59:40,006 that means we just printed 24 in a row. 1307 00:59:40,426 --> 00:59:42,936 >> Thank you. 1308 00:59:43,776 --> 00:59:48,896 >> Questions on that? 1309 00:59:49,166 --> 00:59:53,066 So that's our other shorter outline, 1310 00:59:53,116 --> 00:59:55,986 so we just get all the input, do some calculations 1311 00:59:55,986 --> 00:59:58,846 and then output them using a loop. 1312 01:00:00,136 --> 01:00:02,226 So any questions on anything 1313 01:00:02,226 --> 01:00:06,706 in this problem set before we finish up? 1314 01:00:09,676 --> 01:00:10,796 So other questions? 1315 01:00:10,836 --> 01:00:11,016 Yep? 1316 01:00:11,016 --> 01:00:14,436 >> I would just like to see what a loop looks like again. 1317 01:00:14,506 --> 01:00:16,076 >> Sure. so what a loop looks like, 1318 01:00:16,196 --> 01:00:21,526 so let's open up our style here. 1319 01:00:21,526 --> 01:00:23,616 so this is what a four loop looks like. 1320 01:00:24,586 --> 01:00:26,916 So we have three parts to the four loop. 1321 01:00:27,556 --> 01:00:29,946 And the super section we'll go over this in more detail 1322 01:00:29,946 --> 01:00:31,836 so if you want to look at these slides of the video. 1323 01:00:32,206 --> 01:00:33,646 But basically there's three parts. 1324 01:00:33,646 --> 01:00:36,056 We have the first part, and that is how -- 1325 01:00:36,056 --> 01:00:37,586 what to do before the loop starts. 1326 01:00:37,946 --> 01:00:40,656 So before the loop starts we're creating a variable eye, 1327 01:00:40,656 --> 01:00:42,096 and we're starting it off at zero. 1328 01:00:42,616 --> 01:00:43,606 So this statement is going 1329 01:00:43,606 --> 01:00:45,696 to be executing before anything happens. 1330 01:00:46,576 --> 01:00:48,756 Now what's next is what needs to be happen -- 1331 01:00:48,966 --> 01:00:51,736 what needs to be true before the loop will execute again. 1332 01:00:51,736 --> 01:00:56,126 So we say that the I, our counter variable, has to be less 1333 01:00:56,316 --> 01:00:59,726 than the total number of times we want to execute the loop. 1334 01:01:00,276 --> 01:01:04,626 So this just happens if you ever user told us, and at the end 1335 01:01:04,626 --> 01:01:06,806 of every loop we want to say increment this counter 1336 01:01:07,956 --> 01:01:09,996 so that we don't go too many times. 1337 01:01:10,106 --> 01:01:11,786 So the first on this loop iterates, 1338 01:01:11,786 --> 01:01:12,966 we're going to have I of zero. 1339 01:01:13,376 --> 01:01:15,566 Zero is less than 5 so we're going to print high. 1340 01:01:15,916 --> 01:01:18,406 And now zero is going to go up, so now I is 1. 1341 01:01:19,086 --> 01:01:20,886 So now I is less than 5, so we're going 1342 01:01:20,886 --> 01:01:22,596 to print high, now I is 2. 1343 01:01:22,596 --> 01:01:24,036 So this is going to keep building 1344 01:01:24,036 --> 01:01:25,266 until eventually I is 5. 1345 01:01:25,606 --> 01:01:30,996 Now 5 is not less than 5, so this loop is going to finish. 1346 01:01:31,166 --> 01:01:33,886 So with a wow loop, it's pretty similar. 1347 01:01:33,886 --> 01:01:38,246 We can just say while I is less than iterations, 1348 01:01:38,786 --> 01:01:41,556 we need to make sure that we create I so int I is going 1349 01:01:41,556 --> 01:01:43,796 to create a new variable I, we're going to start it off 1350 01:01:43,796 --> 01:01:48,046 at zero, and so while I is less than the number of insertions, 1351 01:01:48,046 --> 01:01:51,926 we can do something like print high 1352 01:01:52,776 --> 01:01:56,146 and then we want to increment I. 1353 01:01:56,756 --> 01:01:58,956 so just like I plus plus was all the way to the right 1354 01:01:58,956 --> 01:02:03,396 of this force four loop, this is executing once the loop is done, 1355 01:02:03,476 --> 01:02:04,556 so before it loops again. 1356 01:02:05,306 --> 01:02:07,826 So now we're saying while I is less than the total number 1357 01:02:07,826 --> 01:02:08,866 of times you want to do this, 1358 01:02:09,376 --> 01:02:11,466 we're going to do whatever it is you want to do, you know, 1359 01:02:11,466 --> 01:02:14,116 double pennies or something, and then we want to go 1360 01:02:14,116 --> 01:02:15,766 on to the next iteration. 1361 01:02:16,386 --> 01:02:21,056 So those are the two basic loops here. 1362 01:02:21,056 --> 01:02:21,186 Yeah. 1363 01:02:21,186 --> 01:02:21,736 >> [Inaudible] equals 1364 01:02:21,736 --> 01:02:24,256 or you [inaudible] surround the [inaudible]? 1365 01:02:25,016 --> 01:02:28,486 >> So in this case we're always starting I off at zero. 1366 01:02:28,486 --> 01:02:30,866 What we're asking them for is this iterations variable. 1367 01:02:32,346 --> 01:02:35,186 So if I is always zero and then you go into I is less 1368 01:02:35,246 --> 01:02:37,256 than some value, we're going to execute that loop, 1369 01:02:37,576 --> 01:02:40,836 that maximum value a number of times, so that upper bound. 1370 01:02:41,346 --> 01:02:41,446 Yep? 1371 01:02:43,476 --> 01:02:43,666 >> [Inaudible] change [Inaudible] 1372 01:02:43,796 --> 01:02:51,556 >> So the difference between do while and while, so let's say 1373 01:02:51,876 --> 01:02:55,286 that we said int I equals 5 for some reason 1374 01:02:55,286 --> 01:02:58,466 and then iterations is 4. 1375 01:02:58,596 --> 01:03:02,696 So let's say, you know, the user typed in a 4 1376 01:03:02,806 --> 01:03:04,626 and now iterations has a value of 4. 1377 01:03:05,676 --> 01:03:09,996 Now this loop would never execute, because I is not less 1378 01:03:09,996 --> 01:03:12,226 than iterations, 5 is not less than 4, 1379 01:03:12,756 --> 01:03:14,006 so this will never be true. 1380 01:03:14,786 --> 01:03:16,446 If instead we use a do while, 1381 01:03:17,276 --> 01:03:20,386 then we would execute it once then check if it's true 1382 01:03:20,646 --> 01:03:21,976 and never execute it again. 1383 01:03:23,296 --> 01:03:25,006 So the difference is where the check is. 1384 01:03:25,006 --> 01:03:26,196 with the regular while, you're going 1385 01:03:26,196 --> 01:03:28,196 to check before you do anything 1386 01:03:28,466 --> 01:03:30,096 and with the do while you're going to check 1387 01:03:30,236 --> 01:03:34,336 after you do everything. 1388 01:03:35,586 --> 01:03:36,586 Other questions? 1389 01:03:37,006 --> 01:03:37,106 Yep? 1390 01:03:38,846 --> 01:03:43,626 >> If you have a long, long number, does it like display -- 1391 01:03:43,776 --> 01:03:48,106 if you have like a real long number [inaudible] .39 will it 1392 01:03:48,276 --> 01:03:49,926 display that whatever? 1393 01:03:50,836 --> 01:03:52,106 >> So the -- so a long, 1394 01:03:52,106 --> 01:03:54,636 long can't have decimals afterwards, only a float can. 1395 01:03:54,876 --> 01:03:57,416 But Yeah. So if you just printed a really big float it would try 1396 01:03:57,416 --> 01:03:58,086 to print the whole thing. 1397 01:03:58,496 --> 01:03:58,686 >> Okay. 1398 01:04:01,896 --> 01:04:02,956 >> So last questions? 1399 01:04:02,956 --> 01:04:04,586 >> [Inaudible] 1400 01:04:04,586 --> 01:04:08,126 >> So what is the I plus plus? 1401 01:04:08,306 --> 01:04:11,776 So this is the same as saying I equals I plus 1. 1402 01:04:12,066 --> 01:04:12,266 >> Oh. 1403 01:04:12,716 --> 01:04:14,996 >> Yeah. So it's just a shorthand notation to make I go 1404 01:04:14,996 --> 01:04:16,516 up by one or increment I. 1405 01:04:16,846 --> 01:04:18,206 >> Could you write it either way? 1406 01:04:18,236 --> 01:04:18,976 >> Yes, so yes. 1407 01:04:19,086 --> 01:04:20,066 So you could write this either way. 1408 01:04:20,066 --> 01:04:22,296 You could also write this as I plus equals 1, 1409 01:04:22,896 --> 01:04:24,886 which is shorthand for I equals I plus 1, 1410 01:04:25,386 --> 01:04:27,926 which I plus plus is shorthand for. 1411 01:04:28,166 --> 01:04:28,266 Yep? 1412 01:04:28,916 --> 01:04:32,736 >> This is not [inaudible] but when you are closing 1413 01:04:32,736 --> 01:04:34,226 on virtual box can you reopt it 1414 01:04:34,956 --> 01:04:38,846 to say [inaudible] states [inaudible] shut down signal 1415 01:04:39,866 --> 01:04:40,996 and how [inaudible] to do? 1416 01:04:40,996 --> 01:04:42,526 >> Oh so when you're closing virtual box, 1417 01:04:42,526 --> 01:04:43,496 which one should you do? 1418 01:04:43,496 --> 01:04:43,576 >> Yeah. 1419 01:04:43,576 --> 01:04:44,466 >> It probably doesn't matter. 1420 01:04:44,466 --> 01:04:46,106 I usually just do power off the machine, 1421 01:04:46,596 --> 01:04:48,946 but send the machine a shut down signal will be the same 1422 01:04:48,946 --> 01:04:50,696 as like going to start shutdown. 1423 01:04:51,016 --> 01:04:51,936 And power off is the same 1424 01:04:51,936 --> 01:04:54,036 as like hitting the power button, which is faster. 1425 01:04:55,336 --> 01:04:57,586 But not always the best. 1426 01:04:58,366 --> 01:04:59,996 Other questions? 1427 01:05:01,906 --> 01:05:02,126 Oh yeah? 1428 01:05:02,126 --> 01:05:04,996 >> So you were talking about the library 1429 01:05:05,056 --> 01:05:09,746 that uses the math.h. can we use [inaudible] library 1430 01:05:09,886 --> 01:05:12,526 that are [inaudible] which ones we should consider? 1431 01:05:13,206 --> 01:05:14,156 >> So if the problem 1432 01:05:14,286 --> 01:05:16,346 so are there limitations one what libraries we can use 1433 01:05:16,346 --> 01:05:17,736 if the problem set doesn't list any? 1434 01:05:17,736 --> 01:05:18,446 Then yeah, you're free 1435 01:05:18,446 --> 01:05:22,806 to use whatever standard C functions you're using. 1436 01:05:22,906 --> 01:05:25,186 If you use something like you like download something 1437 01:05:25,186 --> 01:05:27,686 from the Internet, first don't download the answer 1438 01:05:27,686 --> 01:05:30,226 to the problem set, but if you download like some function 1439 01:05:30,226 --> 01:05:32,036 from like stack overflow or somewhere, 1440 01:05:32,036 --> 01:05:32,766 make sure you cite it. 1441 01:05:33,126 --> 01:05:35,686 Say someone else wrote this function, I got it from here. 1442 01:05:35,686 --> 01:05:39,066 this is the URL and you'll be good to go. 1443 01:05:39,526 --> 01:05:41,756 But if you're using something in like math.h you don't need 1444 01:05:41,756 --> 01:05:44,286 to document this is from math.h. Yep? 1445 01:05:45,456 --> 01:05:47,456 >> Do you have to [inaudible] download math.h 1446 01:05:47,456 --> 01:05:54,886 like into our directory and the Lenox with it? 1447 01:05:54,886 --> 01:05:58,526 >> No. so math.h is kind of included for you. 1448 01:05:58,856 --> 01:06:01,436 so just like standard IO, .h kind of comes with c 1449 01:06:01,436 --> 01:06:03,126 and the same thing with math. 1450 01:06:03,676 --> 01:06:06,956 >> Where are these [inaudible] math.h? 1451 01:06:07,416 --> 01:06:10,396 >> So these are -- so where are all of these stored? 1452 01:06:10,396 --> 01:06:13,366 At various by computer, but probably inside 1453 01:06:13,416 --> 01:06:15,606 of like user live or something like that. 1454 01:06:15,996 --> 01:06:19,296 If you open up [inaudible] and just like go to the root 1455 01:06:19,496 --> 01:06:21,296 of your computer, which is just slash, 1456 01:06:21,366 --> 01:06:23,026 which is like the equivalent to c or just 1457 01:06:23,026 --> 01:06:24,996 like the highest level possible, then you can poke 1458 01:06:24,996 --> 01:06:26,366 around in there to see where things are. 1459 01:06:26,696 --> 01:06:28,336 But it's different on every installation. 1460 01:06:28,386 --> 01:06:32,856 Any last questions? 1461 01:06:33,706 --> 01:06:33,806 Yep? 1462 01:06:35,236 --> 01:06:45,856 >> In the beginning [inaudible] early on someone asked 1463 01:06:46,456 --> 01:06:54,416 about the main thing that you were supposed to type 1464 01:06:54,416 --> 01:06:56,136 in for the applications like on the website. 1465 01:06:56,136 --> 01:06:58,236 But that doesn't really help [inaudible] do you say 1466 01:06:58,236 --> 01:06:58,386 like [inaudible]? 1467 01:06:58,386 --> 01:06:59,946 >> So if afterwards you just want 1468 01:07:00,536 --> 01:07:07,996 to show me I can give you a better answer by looking at it. 1469 01:07:07,996 --> 01:07:11,386 So just come up here afterwards I can help you out. 1470 01:07:11,386 --> 01:07:11,606 Yep? 1471 01:07:11,606 --> 01:07:12,456 >> Are these are all [inaudible] and the other [inaudible]? 1472 01:07:12,456 --> 01:07:15,346 >> Yes, so you are installing two different things. 1473 01:07:15,346 --> 01:07:21,776 First you're installing virtual box 1474 01:07:22,016 --> 01:07:24,726 and then you're installing the CS50 appliance into virtual box. 1475 01:07:24,756 --> 01:07:25,956 So they're two different things, one of which we made, 1476 01:07:25,986 --> 01:07:26,586 one of which we didn't. 1477 01:07:26,616 --> 01:07:27,576 all right, if there are no more questions 1478 01:07:27,606 --> 01:07:28,416 than good luck on the first PSET. 1479 01:07:28,446 --> 01:07:29,976 Don't forget about help.cs50.net with any questions.