Solution for Exercise 8-19
ex0819
#include <stdio.h> int main() { char choice; puts("Meal Plans:"); puts("A - Breakfast, Lunch, and Dinner"); puts("B - Lunch and Dinner only"); puts("C - Dinner only"); printf("Your choice: "); scanf("%c",&choice); printf("You've opted for "); switch(choice) { case 'A': printf("Breakfast, "); case 'B': printf("Lunch and "); case 'C': printf("Dinner "); default: printf("as your meal plan.\n"); } return(0); }
Notes
* Try various options for input.
* See how the default part of the structure is executed no matter what?
* Without any break statements, execution always falls through this switch-case structure.
Copyright © 1997-2024 by QPBC.
All rights reserved