< previous page page_73 next page >

Page 73
    cout < Halfway between is ;
    cout < avgTemp <  degrees. < endl;

    return 0;
}
The program begins with a comment that explains what the program does. Immediately after the comment, the line
#include <iostream.h>
instructs the C++ system to insert the contents of a file named iostream.h into our program. This file contains information that C++ requires to output values to a stream such as cout. We'll consider exactly what is done by this #include line a little later.
Next comes a declaration section where we define the constants FREEZE_PT and BOIL_PT. Comments explain how each identifier is used. The rest of the program is the function definition for our main function. The first line is the function heading: the reserved word int, the name of the function, and then opening and closing parentheses. (The parentheses inform the compiler that main is the name of a function, not a variable or named constant.) The body of the function includes a declaration of the variable avgTemp and then a list of executable statements. The compiler translates these executable statements into machine language instructions. During the execution phase of the program, these are the instructions that are executed.
Our main function finishes by returning zero as the function value:
return 0;
Remember that main returns an integer value to the operating system when it completes execution. This integer value is called the exit status. On most computer systems, you return an exit status of zero to indicate successful completion of the program; otherwise, you return a nonzero value.
Notice how we use spacing in the FreezeBoil program to make it easy for someone to read. We use blank lines to separate statements into related groups, and we indent the entire body of the main function. The compiler doesn't require us to format the program this way; we do so only to make it more readable. We have more to say in the next chapter about formatting a program.
Blocks (Compound Statements)
The body of a function is an example of a block (or compound statement). This is the syntax template for a block:

 
< previous page page_73 next page >