Mega Code Archive

 
Categories / C Tutorial / Statement
 

Use the switch structure to evaluate a users response from a menu (without break)

#include <stdio.h> main(){   int iResponse = 0;   printf("\nPlease select a category (1-4): ");   scanf("%d", &iResponse);   switch (iResponse) {     case 1:       printf("\nYou selected 1\n");     case 2:       printf("You selected 2\n");     case 3:       printf("You selected 3\n");     case 4:       printf("You selected 4\n");   } //end switch } //end main function Please select a category (1-4): 1 You selected 1 You selected 2 You selected 3 You selected 4