Advertisement
Spocoman

Cinema Tickets

Sep 16th, 2023
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     int seats,
  9.         kidTickets = 0, studentTickets = 0, standardTickets = 0;
  10.  
  11.     string movie, category;
  12.     getline(cin, movie);
  13.  
  14.     while (movie != "Finish") {
  15.         cin >> seats;
  16.         int counter = 0;
  17.  
  18.         for (int i = 0; i < seats; i++) {
  19.             cin >> category;
  20.  
  21.             if (category == "student") {
  22.                 studentTickets++;
  23.             }
  24.             else if (category == "standard") {
  25.                 standardTickets++;
  26.             }
  27.             else if (category == "kid") {
  28.                 kidTickets++;
  29.             }
  30.             else {
  31.                 break;
  32.             }
  33.             counter++;
  34.         }
  35.  
  36.         printf("%s - %.2f%% full.\n", movie.c_str(), 1.0 * counter / seats * 100);
  37.  
  38.         cin.ignore();
  39.         getline(cin, movie);
  40.     }
  41.  
  42.     int sumTickets = standardTickets + studentTickets + kidTickets;
  43.  
  44.     cout.setf(ios::fixed);
  45.     cout.precision(2);
  46.  
  47.     cout << "Total tickets: " << sumTickets << endl
  48.         << 1.0 * studentTickets / sumTickets * 100 << "% student tickets.\n"
  49.         << 1.0 * standardTickets / sumTickets * 100 << "% standard tickets.\n"
  50.         << 1.0 * kidTickets / sumTickets * 100 << "% kids tickets.\n";
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement