The following program receives an integer as input. The output is a sentence that gives the French name for the weekday that is associated with the integer. If the integer is not associated with a weekday, the program prints "C'est le mauvais jour."
/** ** Example program using enumerations **/ #include <stdio.h> enum days { Monday=1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } weekday; void french(enum days); int main(void) { int num; printf("Enter an integer for the day of the week. " "Mon=1,...,Sun=7\n"); scanf("%d", &num); weekday=num; french(weekday); return(0); }
void french(enum days weekday) { switch (weekday) { case Monday: printf("Le jour de la semaine est lundi.\n"); break; case Tuesday: printf("Le jour de la semaine est mardi.\n"); break; case Wednesday: printf("Le jour de la semaine est mercredi.\n"); break; case Thursday: printf("Le jour de la semaine est jeudi.\n"); break; case Friday: printf("Le jour de la semaine est vendredi.\n"); break; case Saturday: printf("Le jour de la semaine est samedi.\n"); break; case Sunday: printf("Le jour de la semaine est dimanche.\n"); break; default: printf("C'est le mauvais jour.\n"); } }
Related References