Sams Teach Yourself C in 21 Days

(singke) #1
170 Week 1

CH 06 94: do
95: {
CH 07 96: printf(“\n\tMonth (0 - 12): “);
CH 07 97: scanf(“%d”, &month[ctr]);
CH 06 98: }while (month[ctr] < 0 || month[ctr] > 12 );
99:
CH 06 100: do
101: {
CH 07 102: printf(“\n\tDay (0 - 31): “);
CH 07 103: scanf(“%d”, &day[ctr]);
CH 06 104: }while ( day[ctr] < 0 || day[ctr] > 31 );
105:
CH 06 106: do
107: {
CH 07 108: printf(“\n\tYear (0 - 2002): “);
CH 07 109: scanf(“%d”, &year[ctr]);
CH 06 110: }while ( year[ctr] < 0 || year[ctr] > 2002 );
111:
CH 07 112: printf(“\nEnter Yearly Income (whole dollars): “);
CH 07 113: scanf(“%ld”, &income[ctr]);
114:
CH 05 115: cont = continue_function();
116: }
CH 07 117: /* ctr equals the number of people that were entered. */
118: }
CH 02 119: /*----------------------------------------------------------*
120: * Function: display_report() *
121: * Purpose: This function displays a report to the screen *
122: * Returns: nothing *
123: * Notes: More information could be printed. *
124: *----------------------------------------------------------*/
125:
CH 05 126: void display_report()
127: {
CH 04 128: grand_total = 0;
CH 07 129: printf(“\n\n\n”); /* skip a few lines */
130: printf(“\n SALARY SUMMARY”);
131: printf(“\n ==============”);
132:
CH 06 133: for( x = 0; x <= 12; x++ ) /* for each month, including 0*/
134: {
135: month_total = 0;
CH 04 136: for( y = 0; y < ctr; y++ )
CH 06 137: {
138: if( month[y] == x )
CH 04 139: month_total += income[y];
CH 04 140: }
141: printf(“\nTotal for month %d is %ld”, x, month_total);
CH 07 142: grand_total += month_total;
CH 04 143: }

LISTINGR1.1 continued

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

Free download pdf