Sams Teach Yourself C in 21 Days

(singke) #1
In Review 171

144: printf(“\n\nReport totals:”);
CH 07 145: printf(“\nTotal Income is %ld”, grand_total);
146: printf(“\nAverage Income is %ld”, grand_total/ctr );
147:
148: printf(“\n\n* * * End of Report * * *\n”);
149: }
CH 02 150: /*----------------------------------------------------------------*
151: * Function: continue_function() *
152: * Purpose: This function asks the user if they wish to continue.*
153: * Returns: YES - if user wishes to continue *
154: * NO - if user wishes to quit *
155: *----------------------------------------------------------------*/
156:
CH 05 157: int continue_function( void )
158: {
CH 07 159: printf(“\n\nDo you wish to continue? (0=NO/1=YES): “);
160: scanf( “%d”, &x );
161:
CH 06 162: while( x < 0 || x > 1 )
163: {
CH 07 164: printf(“\n%d is invalid!”, x);
165: printf(“\nPlease enter 0 to Quit or 1 to Continue: “);
166: scanf(“%d”, &x);
167: }
CH 04 168: if(x == 0)
CH 05 169: return(NO);
CH 04 170: else
CH 05 171: return(YES);
172: }

LISTINGR1.1 continued

After completing the quizzes and exercises on Day 1, “Getting Started with C,”
and Day 2, “The Components of a C Program,” you should be able to enter and
compile this program. This program contains more comments than any other listing
throughout this book. These comments are typical of a “real-world” C program. In par-
ticular, you should notice the comments at the beginning of the program and before each
major function. The comments on lines 1 to 5 give an overview of the entire program,
including the program name. Some programmers also include information such as the
author of the program, the compiler used, its version number, the libraries linked into the
program, and the date on which the program was created. The comments before each
function describe the purpose of the function, possible return values, the function’s call-
ing conventions, and anything relating specifically to that function.
The comments on lines 1 to 5 specify that you can enter information in this program for
up to 100 people. Before you can enter the data, the program calls display_instruc-
tions()on line 45. This function displays instructions for using the program and asks

ANALYSIS

12 448201x-W1R 8/13/02 11:15 AM Page 171

Free download pdf