Sams Teach Yourself C in 21 Days

(singke) #1
Advanced Program Control 325

13


37: delay();
38: break;
39: }
40: case 4:
41: {
42: puts(“\nExecuting task D.”);
43: delay();
44: break;
45: }
46: case 5: /* Exit program. */
47: {
48: puts(“\nExiting program now...\n”);
49: }
50: default:
51: {
52: puts(“\nInvalid choice, try again.”);
53: }
54: } /* End of switch */
55: command = menu();
56: } /* End of while */
57: return 0;
58: }
59:
60: /* Displays a menu and inputs user’s selection. */
61: int menu(void)
62: {
63: int reply;
64:
65: puts(“\nEnter 1 for task A.”);
66: puts(“Enter 2 for task B.”);
67: puts(“Enter 3 for task C.”);
68: puts(“Enter 4 for task D.”);
69: puts(“Enter 5 to exit program.”);
70:
71: scanf(“%d”, &reply);
72:
73: return reply;
74: }
75:
76: void delay( void )
77: {
78: long x;
79: for( x = 0; x < DELAY; x++ )
80: ;
81: }

LISTING13.7 continued

21 448201x-CH13 8/13/02 11:12 AM Page 325

Free download pdf