< previous page page_99 next page >

Page 99
This statement gives us floating point division instead of integer division. As a result, the value 0.75 is stored into average.
As a final remark about type coercion and type conversion, you may have noticed that we have concentrated only on the int and float types. It is also possible to stir char values, short values, and double values into the pot. The results can be confusing and unexpected. In Chapter 10, we return to the topic with a more detailed discussion. In the meantime, you should avoid mixing values of these types within an expression.
Function Calls and Library Functions
Value-Returning Functions
At the beginning of Chapter 2, we showed a program consisting of three functions: main, Square, and club.
int main()
{
    cout << "The square of 27 is " << Square(27) << endl;
    cout << "and the cube of 27 is " << Cube(27) << endl;
    return 0;
}

int Square( int n )
{
    return n * n;
}

int Cube( int n )
{
    return n * n * n;
}
We said that all three functions are value-returning functions. Square returns a value to its caller-the square of the number sent to it. Cube returns a value-the cube of the number sent to it. And main returns a value to the operating system-the program's exit status.
Let's focus for a moment on the Cube function. The main function contains a statement
cout << "and the cube of 27 is " < Cube(27) << endl;
In this statement, the master (main) causes the servant (Cube) to compute the cube of 27 and give the result back to main. The sequence of symbols

 
< previous page page_99 next page >