Loading lessons...
C Project: Build a Mini Menu
Project 1: Interactive Menu
Put loops + conditions + input to work.
The menu
int choice;
do {
printf("1. Print name\n2. Quit\nChoice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Your name? ");
char name[50];
scanf("%49s", name);
printf("Hello, %s!\n", name);
}
} while (choice != 2);
What to save
- do...while keeps showing until 2.
- scanf %49s prevents overflow.
- The same choice drives the loop.
Try extending
Add a 3rd option, or an option that tells if a number is even/odd.
TL;DR
- Menu = loop that reads a choice.
- Validate with conditions.
- Use a built-in do...while until exit.
Good luck building!