// Example
program 1
// Defining, prototyping, and calling a function.
#include <iostream.h>
#include <stdlib.h>
void country(void); // function declaration -
function prototype
int main(void)
{
system("CLS");
cout<< "I'm Joe Main, and I am calling
a function named Country Sue!";
country( ); // function call
return 0;
}
// function definition
void country(void)
{
cout<< "Hi, Joe. Country Sue
here!\n";
return; /* since the return value
is void, NO number is
specified with this return. */
}
Screen:
I'm Joe Main, and I am calling a function named Country Sue!
Hi, Joe. Country Sue here!
|
//Example program 2 with LOCAL variable
// letterhead for a animal shelter
#include <iostream.h>
#include <stdlib.h>
void starline(void); // prototype the
function
int main(void)
{
system("CLS");
starbar( ); // function call
cout<< "\t\t All Creatures Big and
Small Shelter\n";
cout<< "\t\t Lacona, New York \n";
cout<< "\t\t USA \n";
starline( ); // function call
return 0;
}
// function definition
void starline(void)
{
int count; // declaring a LOCAL
variable
for(count = 1; count <=65; count++)
cout<< "*";
cout<<endl;
return;
}
Screen:
*****************************************************************
All Creatures Big and Small Shelter
Lacona, New York
USA
***************************************************************** |
|