|
|
|
|
|
|
|
lines, where the any number of lines is passed as a parameter by the caller (main). Here is a second version of the program, which uses only one function to do the printing. We call it NewWelcome. |
|
|
|
|
|
|
|
|
//******************************************************************
// NewWelcome program
// This program prints a Welcome Home message
//******************************************************************
#include <iostream.h>
void PrintLines( int ); // Function prototype
int main()
{
PrintLines(2);
cout << Welcome Home! << endl;
PrintLines(4);
return 0;
}
//******************************************************************
void PrintLines( int numLines )
// This function prints lines of asterisks, where
// numLines specifies how many lines to print
{
int count; // Loop control variable
count = 1;
while (count <= numLines)
{
cout << *************** << endl;
count++;
}
} |
|
|
|
|
|
|
|
|
In the function heading of PrintLines, you see some code between the parentheses that looks like a variable declaration. This is a parameter declaration. As you learned in earlier chapters, parameters represent a way for two functions to communicate with each other. Parameters enable the calling function to input (pass) values to another function to use in its processing andin some casesto allow the called function to output (return) results to the caller. The parameters in the call to a function are the actual parameters. The parameters listed in the function heading are the formal |
|
|
|
|
|