Chap06-functions

Chap06-functions - / This program has two functions: main...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
// This program has two functions: main and displayMessage #include <iostream> using namespace std; //***************************************** // Definition of function displayMessage * // This function displays a greeting. * //***************************************** void displayMessage() { cout << "Hello from the function displayMessage.\n" ; } int main() { cout << "Hello from main.\n" ; displayMessage(); // Call displayMessage cout << "Back in function main again.\n" ; return 0; } -------------------------------------------------------------------------------------------------------------------------------- // The function displayMessage is repeatedly called from within a loop. #include <iostream> using namespace std; //***************************************** // Definition of function displayMessage * // This function displays a greeting. * //***************************************** void displayMessage() { cout << "Hello from the function displayMessage.\n" ; } int main() { cout << "Hello from main.\n" ; for ( int count = 0; count < 5; count++) displayMessage(); // Call displayMessage cout << "Back in function main again.\n" ; return 0; } -------------------------------------------------------------------------------------------------------------------------------- // This program has three functions: main, deep, and deeper #include <iostream> using namespace std; //*************************************** // Definition of function deeper * // This function displays a message. *
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
//*************************************** void deeper() { cout << "I am now inside the function deeper.\n" ; } //*************************************** // Definition of function deep * // This function calls function deeper. * //*************************************** void deep() { cout << "I am now inside the function deep.\n" ; deeper(); // Call function deeper cout << "Now I am back in deep.\n" ; } int main() { cout << "I am starting in function main.\n" ; deep(); // Call function deep cout << "Back in function main again.\n" ; return 0; } -------------------------------------------------------------------------------------------------------------------------------- // This program has three functions: main, first, and second. // It uses function prototypes. #include <iostream> using namespace std; // Function prototypes void first(); void second(); int main() { cout << "I am starting in function main.\n" ; first(); // Call function first second(); // Call function second cout << "Back in function main again.\n" ; return 0; } //********************************************* // Definition of function first * // This function displays a message. * //********************************************* void first() { cout << "I am now inside the function first.\n" ; } //*********************************************
Background image of page 2
// Definition of function second * // This function displays a message. * //********************************************* void second() { cout << "I am now inside the function second.\n"
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

Chap06-functions - / This program has two functions: main...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online