11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

140Part II: Becoming a Functional C++ Programmerprogram as these different output statements are executed. A second approachis to use a separate program called a debugger. A debugger enables you to controlyour program as it executes.I cover both of these debugging techniques in this chapter.Choosing the WRITE Technique for the ProblemAdding output statements to the C++ source code to find out what’s going onwithin the program is known as using the WRITE statement approach. Itgained this name back in the days of early programs when programs werewritten mostly in COBOL and FORTRAN. Fortran’s output is through theWRITE command.The following “buggy” program shows how the WRITE approach works.The following program is supposed to read a series of numbers from the keyboardand return their average. Unfortunately, the program contains twoerrors, one that makes the program crash and one that causes the programto generate incorrect results.The following steps route out the problem. First, enter the program as written(or copy the program ErrorProgram1.cpp from the CD-ROM).// ErrorProgram - this program averages a series// of numbers, except that it contains// at least one fatal bug#include #include #include using namespace std;int main(int nNumberofArgs, char* pszArgs[]){cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!