< Previous | Contents | Next >

Introducing the Instructions Program

The results of the Instructions program are pretty basica few lines of text that are the beginning of some game instructions. From the looks of the output, Instructions seems like a program you could have written way back in Chapter 1. But this program has a fresh element working behind the scenesa new function. Take a look at Figure 5.1 to see the modest results of the code.



image

Figure 5.1

The instructions are displayed by a function.


You can download the code for this program from the Course Technology website (www.courseptr.com/downloads). The program is in the Chapter 5 folder; the filename is instructions.cpp.

// Instructions

// Demonstrates writing new functions #include <iostream>

using namespace std;


// function prototype (declaration) void instructions();

Creating Functions 153



int main()

{

instructions(); return 0;

}


// function definition void instructions()

{

cout << "Welcome to the most fun you’ve ever had with text!\n\n"; cout << "Here’s how to play the game.. .\n";

}