Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define PRICE_NORMAL 7
- #define PRICE_WEEKEND 10
- #define DISCOUNT_CHILD 0.5
- #define DISCOUNT_OLD 0.3
- typedef enum { SUN,
- MON,
- TUE,
- WED,
- THU,
- FRI,
- SAT } WeekDay;
- typedef enum { CHILD,
- ADULT,
- SENIOR,
- INVALID = -1
- } Class;
- void strupr1 (char* str) {
- for (int i=0; str[i] != '\0'; ++i) {
- if (str[i] >= 'a' && str[i] <= 'z') {
- str[i] -= 32;
- }
- }
- return;
- }
- int main () {
- WeekDay day;
- int age1, age2, age3, n;
- char movie1[30], movie2[30], movie3[30];
- printf("What day is it today?\n(%d=SUN, %d=MON, %d=TUE, %d=WED, %d=THU, %d=FRI, %d=SAT): ",
- SUN, MON, TUE, WED, THU, FRI, SAT);
- scanf("%d", &day);
- printf("How many people of you? ");
- scanf("%d", &n);
- if (n >= 1) {
- printf("\n\nPlease enter the age of the 1st people: ");
- scanf("%d", &age1);
- age1 = age1 >= 0 ? (age1 >= 18 ? (age1 >= 65 ? SENIOR : ADULT) : CHILD) : -1;
- if (age1 == INVALID)
- printf("Your value you enterd is invalid.\n");
- printf("What movie would you want: ");
- while (getchar() != '\n');
- scanf("%[^\n]", movie1);
- strupr1(movie1);
- }
- if (n >= 2) {
- printf("\nPlease enter the age of the 2nd people: ");
- scanf("%d", &age2);
- age2 = age2 >= 0 ? (age2 >= 18 ? (age2 >= 65 ? SENIOR : ADULT) : CHILD) : -1;
- if (age2 == INVALID)
- printf("Your value you enterd is invalid.\n");
- printf("What movie would you want: ");
- while (getchar() != '\n');
- scanf("%[^\n]", movie2);
- strupr1(movie2);
- }
- if (n>=3) {
- printf("\nPlease enter the age of the 3rd people: ");
- scanf("%d", &age3);
- age3 = age3 >= 0 ? (age3 >= 18 ? (age3 >= 65 ? SENIOR : ADULT) : CHILD) : -1;
- if (age3 == INVALID)
- printf("Your value you enterd is invalid.\n");
- printf("What movie would you want: ");
- while (getchar() != '\n');
- scanf("%[^\n]", movie3);
- strupr1(movie3);
- }
- printf("\n%d ticket(s) for you:\n\n", n);
- if (n >= 1) {
- if (age1 != INVALID) {
- float price;
- if (day==SUN || day==SAT)
- price = PRICE_WEEKEND;
- else
- price = PRICE_NORMAL;
- if (age1 == CHILD)
- price *= (1 - DISCOUNT_CHILD);
- else if (age1 == SENIOR)
- price *= 1 - DISCOUNT_OLD;
- printf("----------------------------------------\n");
- printf("|%*s%s%*s|\n", 12, "", "TICKET & BILL", 13, "");
- printf("|%*s|\n", 38, "");
- printf("|--------------------------------------|\n");
- printf("|%-*s%-*s|\n", 10, "MOVIE:", 28, movie1);
- printf("|%*s|\n", 38, "");
- printf("|%-*s%-*s|\n", 10, "Class: ", 28, age1 == CHILD ? "Child" : (age1 == ADULT ? "Adult" : "Senior Citizen"));
- printf("|%-*s%-*s|\n", 10, "Date: ", 28, (day == SUN || day == SAT) ? "Weekend" : "Normal");
- printf("|%-*s$%-*.2f|\n", 10, "Price: ", 27, price);
- printf("|%*s|\n", 38, "");
- printf("----------------------------------------\n");
- } else
- printf("Information of the 1st people is invalid.\n");
- }
- if (n >= 2) {
- if (age2 != INVALID) {
- float price;
- if (day==SUN || day==SAT)
- price = PRICE_WEEKEND;
- else
- price = PRICE_NORMAL;
- if (age2 == CHILD)
- price *= (1 - DISCOUNT_CHILD);
- else if (age2 == SENIOR)
- price *= 1 - DISCOUNT_OLD;
- printf("\n----------------------------------------\n");
- printf("|%*s%s%*s|\n", 12, "", "TICKET & BILL", 13, "");
- printf("|%*s|\n", 38, "");
- printf("|--------------------------------------|\n");
- printf("|%-*s%-*s|\n", 10, "MOVIE:", 28, movie2);
- printf("|%*s|\n", 38, "");
- printf("|%-*s%-*s|\n", 10, "Class: ", 28, age2 == CHILD ? "Child" : (age2 == ADULT ? "Adult" : "Senior Citizen"));
- printf("|%-*s%-*s|\n", 10, "Date: ", 28, (day == SUN || day == SAT) ? "Weekend" : "Normal");
- printf("|%-*s$%-*.2f|\n", 10, "Price: ", 27, price);
- printf("|%*s|\n", 38, "");
- printf("----------------------------------------\n");
- } else
- printf("Information of the 2nd people is invalid.\n");
- }
- if (n >= 3) {
- if (age3 != INVALID) {
- float price;
- if (day==SUN || day==SAT)
- price = PRICE_WEEKEND;
- else
- price = PRICE_NORMAL;
- if (age3 == CHILD)
- price *= (1 - DISCOUNT_CHILD);
- else if (age3 == SENIOR)
- price *= 1 - DISCOUNT_OLD;
- printf("\n----------------------------------------\n");
- printf("|%*s%s%*s|\n", 12, "", "TICKET & BILL", 13, "");
- printf("|%*s|\n", 38, "");
- printf("|--------------------------------------|\n");
- printf("|%-*s%-*s|\n", 10, "MOVIE:", 28, movie3);
- printf("|%*s|\n", 38, "");
- printf("|%-*s%-*s|\n", 10, "Class: ", 28, age3 == CHILD ? "Child" : (age3 == ADULT ? "Adult" : "Senior Citizen"));
- printf("|%-*s%-*s|\n", 10, "Date: ", 28, (day == SUN || day == SAT) ? "Weekend" : "Normal");
- printf("|%-*s$%-*.2f|\n", 10, "Price: ", 27, price);
- printf("|%*s|\n", 38, "");
- printf("----------------------------------------\n");
- } else
- printf("Information of the 3rd people is invalid.\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement