/* * switch1.c */ #include // include functions in stdio.h when compiling int main(void) // header for main, returns int, takes nothing { char userchoice; // declare char char character; // declare char printf("\nPlease enter one lowercase letter: "); // prompt user for input scanf("%c", &character); // read from stdin, // interpret as a char, // store at location of variable character getchar(); // fluch input buffer printf("\n\nThis program Provides 3 Options: \n"); printf("1) Display the ascii number for the character \n"); printf("2) Display the upper case of the character \n"); printf("3) Display the upper case of the character "); printf(" and it's ascii value\n\n"); printf("Choose: "); scanf("%c", &userchoice); // read from stdin, // interpret as a char, // store at location of variable userchoice getchar(); // flush input buffer printf("\n\n You provided the %c character\n", character); printf("and the requested option %c\n", userchoice); switch(userchoice) // value of variable given to switch { case '1': printf("The ascii number for %c is %d.\n\n",character,character); break; // leave case, go to next bit of code case '2': printf("The upper case for %c is %c.\n\n",character,(character-32)); break; // leave case, go to next bit of code case '3': printf("The upper case for %c is %c,%d.\n\n",character,(character-32),(character-32)); break; // leave case, go to next bit of code default: printf("\n %c ?? You must choose 1, 2, or 3\n\n", userchoice); } return 0; }