logo

The switch statement in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int fruit = 2; printf("What fruit would you like? "); scanf("%d", &fruit); switch (fruit) { case 0: printf("You selected apples\n"); break; case 1: printf("You selected lemons\n"); break; case 2: printf("You selected oranges\n"); break; default: printf("No such fruit\n"); break; } return 0; }

Courses with this lesson