Sams Teach Yourself C in 21 Days

(singke) #1
In Review 381

146:
147: /*-----------------------------------------------------------*
148: * Function: display_report() *
149: * Purpose: This function displays a report to the screen *
150: * Returns: nothing *
151: * Notes: More information could be displayed. *
152: * Change stdout to stdprn to Print report *
153: *-----------------------------------------------------------*/
154:
155: void display_report()
156: {
CH 12 157: long month_total = 0,
158: grand_total = 0; /* For totals */
CH 12 159: int x, y;
160:
CH 14 161: fprintf(stdout, “\n\n”); /* skip a few lines */
162: fprintf(stdout, “\n REPORT”);
163: fprintf(stdout, “\n ========”);
164:
165: for( x = 0; x <= 12; x++ ) /* for each month, including 0 */
166: {
167: month_total = 0;
168: for( y = 0; y < last_entry; y++ )
169: {
170: if( list[y].month == x )
171: {
172: fprintf(stdout,”\n\t%s %s %s %ld”,list[y].fname,
CH 11 173: list[y].lname, list[y].phone,list[y].income);
174: month_total += list[y].income;
175: }
176: }
CH 14 177: fprintf(stdout, “\nTotal for month %d is %ld”,x,month_total);
178: grand_total += month_total;
179: }
180: fprintf(stdout, “\n\nReport totals:”);
181: fprintf(stdout, “\nTotal Income is %ld”, grand_total);
182: fprintf(stdout, “\nAverage Income is %ld”, grand_total/last_entry );
183:
184: fprintf(stdout, “\n\n* * * End of Report * * *”);
185: }
186:
187: /*-------------------------------------------------------------------*
188: * Function: continue_function() *
189: * Purpose: This function asks the user if they wish to continue. *
190: * Returns: YES - if user wishes to continue *
191: * NO - if user wishes to quit *
192: *-------------------------------------------------------------------*/
193:
194: int continue_function( void )
195: {

LISTINGR2.1 continued

23 448201x-W2R 8/13/02 11:12 AM Page 381

Free download pdf