Sams Teach Yourself C in 21 Days

(singke) #1
Advanced Program Control 323

13


8:
9: puts(“\nEnter a number between 1 and 5:”);
10: scanf(“%d”, &reply);
11:
12: switch (reply)
13: {
14: case 0:
15: break;
16 case 1:
17: {
18: puts(“You entered 1.\n”);
19: break;
20: }
21: case 2:
22: {
23: puts(“You entered 2.\n”);
24: break;
25: }
26: case 3:
27: {
28: puts(“You entered 3.\n”);
29: break;
30: }
31: case 4:
32: {
33: puts(“You entered 4.\n”);
34: break;
35: }
36: case 5:
37: {
38: puts(“You entered 5.\n”);
39: break;
40: }
41: default:
42: {
43: puts(“Out of range, try again.\n”);
44: }
45: } /* End of switch */
46: return 0;
47: }

Enter a number between 1 and 5:
1
You entered 1.

LISTING13.6 continued

INPUT/
OUTPUT

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

Free download pdf