-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17ex1.c
54 lines (47 loc) · 1.42 KB
/
17ex1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Example program #1 from Chapter 17 of Absolute Beginner's Guide
//to C, 3rd Edition
// File 17ex1.c
/* This program presents a menu of choices, gets the user's choice,
and then uses the switch statement to execute a line or two of code
based on that choice. (What the user wants to do is not truly
implemented-it is just a series of stubs to teach the value of the
switch statement.) */
#include <stdio.h>
#include <stdlib.h>
main()
{
int choice;
printf("What do you want to do?\n");
printf("1. Add New Contact\n");
printf("2. Edit Existing Contact\n");
printf("3. Call Contact\n");
printf("4. Text Contact\n");
printf("5. Exit\n");
do
{
printf("Enter your choice: ");
scanf(" %d", &choice);
switch (choice)
{
case(1): printf("\nTo add you will need the ");
printf("contact's\n");
printf("First name, last name, and number.\n");
break;
case (2): printf("\nGet ready to enter the name of ");
printf("name of the\n");
printf("contact you wish to change.\n");
break;
case (3): printf("\nWhich contact do you? ");
printf("wish to call?\n");
break;
case (4): printf("\nWhich contact do you ");
printf("wish to text? \n");
break;
case (5): exit(1); // Exists the program early
default: printf("\n%d is not a valid choice.\n", choice);
printf("Try again. \n");
break;
}
} while ((choice < 1) || (choice > 5));
return 0;
}