Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define ROWS 5
  4. #define SEATS_IN_ROW 3
  5.  
  6. #define CHEAP_TICKET_PRICE 25
  7. #define NORMAL_TICKET_PRICE 35
  8. #define VIP_TICKET_PRICE 50
  9.  
  10. void printCinema(int cinema[][SEATS_IN_ROW], int rows);
  11. int buy_tickets(int seats[][SEATS_IN_ROW], int row, int seatInRow);
  12. int popcorn_amount(int seats[][SEATS_IN_ROW]);
  13. void club_member(int seats[ROWS][SEATS_IN_ROW], int row, int seatInRow);
  14. void owner_gone_mad(int seats[][SEATS_IN_ROW], int newPrice);
  15.  
  16.  
  17. int main(void)
  18. {
  19.  
  20. int choice = 0;
  21.  
  22. int row = 0;
  23. int seatInRow = 0;
  24. int returnValue = 0;
  25. int newSeatPrice = 0;
  26.  
  27. int cinema[ROWS][SEATS_IN_ROW] = {{CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE},
  28. {NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE},
  29. {NORMAL_TICKET_PRICE, VIP_TICKET_PRICE, NORMAL_TICKET_PRICE},
  30. {NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE, NORMAL_TICKET_PRICE},
  31. {CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE, CHEAP_TICKET_PRICE}};
  32.  
  33.  
  34. printf("Welcome to cinema.\n");
  35. printf("Print cinema = 1\n");
  36. printf("Buy a ticket = 2\n");
  37. printf("Calculate amount of popcorn = 3\n");
  38. printf("Club member discount = 4\n");
  39. printf("Owner be crazy = 5\n");
  40. printf("Exit program = 6\n");
  41.  
  42. while(choice != 6)
  43. {
  44. printf("Enter new choice:\n");
  45. scanf(" %d", &choice);
  46.  
  47. switch(choice)
  48. {
  49. case 1:
  50. printCinema(cinema, 0);
  51. break;
  52. case 2:
  53. printf("Choose row:\n");
  54. scanf(" %d", &row);
  55. printf("Choose seat number:\n");
  56. scanf(" %d", &seatInRow);
  57. returnValue = buy_tickets(cinema, row, seatInRow);
  58. if (returnValue==1)
  59. {
  60. printf("Purchase sucssesful.\n");
  61. }
  62. else
  63. {
  64. printf("Purchase not sucssesful.\n");
  65. }
  66. break;
  67. case 3:
  68. printf("Amount of popcorn to be made: %d\n", popcorn_amount(cinema));
  69. break;
  70. case 4:
  71. printf("Choose row:\n");
  72. scanf(" %d", &row);
  73. printf("Choose seat number:\n");
  74. scanf(" %d", &seatInRow);
  75. club_member(cinema, row, seatInRow);
  76. break;
  77. case 5:
  78. printf("Choose new seat price:\n");
  79. scanf(" %d", &newSeatPrice);
  80. owner_gone_mad(cinema, newSeatPrice);
  81. break;
  82. case 6:
  83. printf("Thanks for using my cinema.\n");
  84. return 0;
  85. }
  86. }
  87.  
  88. return 0;
  89. }
  90.  
  91. /**
  92. Print a cinema hall ticket prices
  93. Input: hall, and number of rows
  94. Output: None
  95. */
  96. void printCinema(int mat[][SEATS_IN_ROW], int rows)
  97. {
  98. int row = 0;
  99. int col = 0;
  100. for(row = 0; row<ROWS; row++)
  101. {
  102. for(col = 0 ; col<SEATS_IN_ROW ; col++)
  103. {
  104. printf("%d ", mat[row][col]);
  105. }
  106. printf("\n");
  107. }
  108. }
  109.  
  110. int buy_tickets(int seats[][SEATS_IN_ROW], int row, int seatInRow)
  111. {
  112. if(seats[row][seatInRow]!=-1)
  113. {
  114. seats[row][seatInRow] = -1;
  115. return 1; //if seat is empty.
  116. }
  117.  
  118. return 0; //if seat isnt empty.
  119. }
  120.  
  121. int popcorn_amount(int seats[][SEATS_IN_ROW])
  122. {
  123. int row = 0;
  124. int col = 0;
  125. int takenSeats = 0;
  126.  
  127. for(row = 0; row<ROWS; row++)
  128. {
  129. for(col = 0; col<SEATS_IN_ROW; col++)
  130. {
  131. if(seats[row][col]==-1)
  132. {
  133. takenSeats = takenSeats+1;
  134. }
  135. }
  136. }
  137.  
  138. return takenSeats;
  139. }
  140.  
  141. void club_member(int seats[][SEATS_IN_ROW], int row, int seatInRow)
  142. {
  143.  
  144. if(seats[row][seatInRow]!=-1)
  145. {
  146. seats[row][seatInRow] = seats[row][seatInRow] - seats[row][seatInRow] * 0.1;
  147. }
  148. }
  149.  
  150.  
  151. void owner_gone_mad(int seats[][SEATS_IN_ROW], int newPrice)
  152. {
  153. int row = 0;
  154. int col = 0;
  155.  
  156. for(row = 0; row<ROWS; row++)
  157. {
  158. for(col = 0; col<SEATS_IN_ROW; col++)
  159. {
  160. if(seats[row][col]!=-1)
  161. {
  162. seats[row][col] = newPrice;
  163. }
  164. }
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement