Mega Code Archive

 
Categories / C Tutorial / Statement
 

Two cases, one action

#include <stdio.h> int main(void) {   char answer = 0;   printf("Enter Y or N: ");   scanf(" %c", &answer);   switch (answer)   {     case 'y': case 'Y':       printf("\nYou responded in the affirmative.");       break;     case 'n': case 'N':       printf("\nYou responded in the negative.");       break;     default:       printf("\nYou did not respond correctly...");       break;   }   return 0; } Enter Y or N: N You responded in the negative.