[MUSIC] Okay, so we need more practice with output. Output is a very important component of programming. And we know the famous expression, garbage in garbage out, and it wouldn't be useful in most cases that have programs that don't produce answers. So I'll put it as critical. So let's look at a program that's going to convert a marathon distance from miles in yards to kilometers. Here's a program, the distance marathon in kilometers. Now again, that first part that I've just highlighted is a comment. A comment is just something that gets thrown away. So why do we have comments if it gets thrown away? Well we need to make our code readable for a variety of reasons. First off, somebody needs to maintain the program. They have to understand what the program is being used for. What's the history of how the program got developed? So we typically like to put in when the program was last updated or coded and by who, and some overall comment as to the use of the program. Now the first thing that actually shows up in the C code is what's called a pre-processor command, that's the sharp include. And inside the angle brackets we see stdio.h, and the .h is an extension that intent that means a header file, and that means that in this file which will be included automatically with our program. So it's called pre-processor because it happens before the C code is compiled. So extra code gets added, and that code is the code that we're going to need for doing printf. Without it the printf would be undeclared. Then we start the actual code, and that's with the keyword int which means that the function called main, and almost always, fact in our beginning course, everything will always have a main. Main will be where the program executes from, that's understood by the C system. Void is another key word meaning no arguments. So int is a keyword meaning that the program returns an integer. Void is a key word that would if it's used as a data type means it's an undefined data type, or in this case it means that the argument list is empty. The next thing we see is this brace, an open brace means begin the code. In programming languages there are a lot of matching braces. We've already seen matching, wait, we've seen the star asterisk match, we've seen the angle brackets match, we've seen the parentheses match. Very critical to getting syntax right is to make sure you don't improperly match braces. So for this brace there's a closing brace, and this is called a compound statement. It's a series of statements that is the executable code here. We have two simple variables that are integer type. And this called the declaration, and it's a declaration with initialization. So miles is initialized to 26, yards is initialized to 385. And a good programmer chooses identifier names, miles in yards are identifiers. Why choose something like that rather than m and y? M and y might be okay, but it adds documentation at no cost. So the fact that we use an actual word like miles or yards gives the program more literacy, makes the program more literate. And then the result is going to be again a literate identifier, but this time of type double and it's going to be kilometers. And then the formula is kilometers is assigned 1.609 times miles plus yards divided by 1760.0. I'm going to mention this because it's important and it will be re-emphasized later on. The reason that we didn't choose to use 1760 is that yards is an integer, this would be an integer, and if we did this without making this in effect a double constant, then this would have given rise to 0. We would have gotten the integer division of yards with 1760, and 385 over 1760 when they both are integer is 0. So we could do this later. We'll learn that we can also use a cast. Another trick would have been to say 1.0 times yards divide by 1760. And what happens is there's an explicit conversion which takes the more extensive type and makes the whole expression be of that type. And then we have the print statement. And in the print statement we first have the controlling format expression, which is a string. So again, you see matching quotes. At an earlier time I left out one of these quotes and you get a syntax merit. So you should see what happens, if you leave out one of the matches you'll see you get very different kind and sometimes obscure syntax errors. But this says print a new line, which means advance on the screen. A marathon is, this says use a long float or double format, print kilometers period and then two new lines, and then kilometers is in fact interpreted and printed as a long float. And then return zero because we told you that int has a integer value and so that returns zero, and mysteriously that returns zero to the operating system. Zero being a code that the program ended correctly. So let's execute this. And indeed we get a correct result, that a marathon is 42.185969 kilometers. Okay, so study this program. It's a little more complicated than the previous program, but it gives you a lot of critical ideas. And we'll go into the various things that were talked about in later lectures in more detail. [MUSIC]