Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROWS 5
- #define SEATS_IN_ROW 3
- #define CHEAP_TICKET_PRICE 25
- #define NORMAL_TICKET_PRICE 35
- #define VIP_TICKET_PRICE 50
- void printCinema(int cinema[][SEATS_IN_ROW], int rows);
- int buy_tickets(int seats[][SEATS_IN_ROW], int row, int seatInRow);
- int popcorn_amount(int seats[][SEATS_IN_ROW]);
- void club_member(int seats[ROWS][SEATS_IN_ROW], int row, int seatInRow);
- void owner_gone_mad(int seats[][SEATS_IN_ROW], int newPrice);
- int main(void)
- {
- int choice = 0;
- int row = 0;
- int seatInRow = 0;
- int returnValue = 0;
- int newSeatPrice = 0;
- int cinema[ROWS][SEATS_IN_ROW] = {{CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE},
- {NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE},
- {NORMAL_TICKET_PRICE, VIP_TICKET_PRICE, NORMAL_TICKET_PRICE},
- {NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE},
- {CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE}};
- printf("Welcome to cinema.\n");
- printf("Print cinema = 1\n");
- printf("Buy a ticket = 2\n");
- printf("Calculate amount of popcorn = 3\n");
- printf("Club member discount = 4\n");
- printf("Owner be crazy = 5\n");
- printf("Exit program = 6\n");
- while(choice != 6)
- {
- printf("Enter new choice:\n");
- scanf(" %d", &choice);
- switch(choice)
- {
- case 1:
- printCinema(cinema, 0);
- break;
- case 2:
- printf("Choose row:\n");
- scanf(" %d", &row);
- printf("Choose seat number:\n");
- scanf(" %d", &seatInRow);
- returnValue = buy_tickets(cinema, row, seatInRow);
- if (returnValue==1)
- {
- printf("Purchase sucssesful.\n");
- }
- else
- {
- printf("Purchase not sucssesful.\n");
- }
- break;
- case 3:
- printf("Amount of popcorn to be made: %d\n", popcorn_amount(cinema));
- break;
- case 4:
- printf("Choose row:\n");
- scanf(" %d", &row);
- printf("Choose seat number:\n");
- scanf(" %d", &seatInRow);
- club_member(cinema, row, seatInRow);
- break;
- case 5:
- printf("Choose new seat price:\n");
- scanf(" %d", &newSeatPrice);
- owner_gone_mad(cinema, newSeatPrice);
- break;
- case 6:
- printf("Thanks for using my cinema.\n");
- return 0;
- }
- }
- return 0;
- }
- /**
- Print a cinema hall ticket prices
- Input: hall, and number of rows
- Output: None
- */
- void printCinema(int mat[][SEATS_IN_ROW], int rows)
- {
- int row = 0;
- int col = 0;
- for(row = 0; row<ROWS; row++)
- {
- for(col = 0 ; col<SEATS_IN_ROW ; col++)
- {
- printf("%d ", mat[row][col]);
- }
- printf("\n");
- }
- }
- int buy_tickets(int seats[][SEATS_IN_ROW], int row, int seatInRow)
- {
- if(seats[row][seatInRow]!=-1)
- {
- seats[row][seatInRow] = -1;
- return 1; //if seat is empty.
- }
- return 0; //if seat isnt empty.
- }
- int popcorn_amount(int seats[][SEATS_IN_ROW])
- {
- int row = 0;
- int col = 0;
- int takenSeats = 0;
- for(row = 0; row<ROWS; row++)
- {
- for(col = 0; col<SEATS_IN_ROW; col++)
- {
- if(seats[row][col]==-1)
- {
- takenSeats = takenSeats+1;
- }
- }
- }
- return takenSeats;
- }
- void club_member(int seats[][SEATS_IN_ROW], int row, int seatInRow)
- {
- if(seats[row][seatInRow]!=-1)
- {
- seats[row][seatInRow] = seats[row][seatInRow] - seats[row][seatInRow] * 0.1;
- }
- }
- void owner_gone_mad(int seats[][SEATS_IN_ROW], int newPrice)
- {
- int row = 0;
- int col = 0;
- for(row = 0; row<ROWS; row++)
- {
- for(col = 0; col<SEATS_IN_ROW; col++)
- {
- if(seats[row][col]!=-1)
- {
- seats[row][col] = newPrice;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement