Created
January 29, 2014 09:42
-
-
Save Yago/971c4858ed16fe70abf1 to your computer and use it in GitHub Desktop.
C - Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If/else /////////////////////////////////// | |
if (age == 2){ | |
printf("Salut bebe !"); | |
}else if (age == 6){ | |
printf("Salut gamin !"); | |
}else if (age == 12){ | |
printf("Salut jeune !"); | |
}else if (age == 16){ | |
printf("Salut ado !"); | |
}else if (age == 18){ | |
printf("Salut adulte !"); | |
}else if (age == 68){ | |
printf("Salut papy !"); | |
}else{ | |
printf("Je n'ai aucune phrase de prete pour ton age"); | |
} | |
// Switch /////////////////////////////////// | |
switch (age){ | |
case 2: | |
printf("Salut bebe !"); | |
break; | |
case 6: | |
printf("Salut gamin !"); | |
break; | |
case 12: | |
printf("Salut jeune !"); | |
break; | |
case 16: | |
printf("Salut ado !"); | |
break; | |
case 18: | |
printf("Salut adulte !"); | |
break; | |
case 68: | |
printf("Salut papy !"); | |
break; | |
default: | |
printf("Je n'ai aucune phrase de prete pour ton age "); | |
break; | |
} | |
// Example : /////////////////////////////////// | |
int main(int argc, const char * argv[]) | |
{ | |
int choix; | |
printf("======= Menu ? choix =======\n"); | |
printf("1. Salade de couscous ? l'orange\n"); | |
printf("2. Kebab ? l'aubergine\n"); | |
printf("3. Fricass?e de caille aux ?pinard\n"); | |
printf("4. Mousse de Homard aux herbes du maquis\n"); | |
printf("\nVotre choix ? "); | |
scanf("%d", &choix); | |
switch(choix){ | |
case 1: | |
printf("Vous avez choisi la salade !\n"); | |
break; | |
case 2: | |
printf("Vous avez choisi le kebab !\n"); | |
break; | |
case 3: | |
printf("Vous avez choisi la fricass?e !\n"); | |
break; | |
case 4: | |
printf("Vous avez choisi la mousse !\n"); | |
break; | |
default: | |
printf("Vous n'avez pas rentre un nombre correct. Vous ne mangerez rien du tout !"); | |
break; | |
} | |
printf("\n\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment