Solution for Exercise 8-20
ex0820
#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': case 'a': printf("Breakfast, "); case 'B': case 'b': printf("Lunch and "); case 'C': case 'c': printf("Dinner "); default: printf("as your meal plan.\n"); } return(0); }
Notes
* By doubling up on the case structures, using two of them back-to-back for upper and lower case results, you handle any type of proper input.
* C offers other ways to deal with upper and lower case differences, as described in my book.
Copyright © 1997-2024 by QPBC.
All rights reserved