desislava_topuzakova

06. Cinema Tickets

Feb 14th, 2022
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string movie;
  8.     getline(cin >> ws, movie);
  9.  
  10.     int allSoldCnt = 0;
  11.  
  12.     cout.setf(ios::fixed);
  13.     cout.precision(2);
  14.  
  15.     int student = 0, standard = 0, kid = 0;
  16.  
  17.     while (movie != "Finish")
  18.     {
  19.         int allPerMovie;
  20.         cin >> allPerMovie;
  21.  
  22.         int currAllSold = 0;
  23.         int allAvailable = allPerMovie;
  24.  
  25.         string ticketType;
  26.  
  27.         while (allAvailable != 0)
  28.         {
  29.             cin >> ticketType;
  30.             if (ticketType == "End")
  31.             {
  32.                 break;
  33.             }
  34.             allAvailable--;
  35.             allSoldCnt++;
  36.             currAllSold++;
  37.  
  38.             if (ticketType == "student")
  39.             {
  40.                 student++;
  41.             }
  42.             else if (ticketType == "standard")
  43.             {
  44.                 standard++;
  45.             }
  46.             else if (ticketType == "kid")
  47.             {
  48.                 kid++;
  49.             }
  50.         }
  51.  
  52.         cout << movie << " - " << currAllSold * 100.0 / allPerMovie << "% full." << endl;
  53.  
  54.         getline(cin >> ws, movie);
  55.     }
  56.  
  57.     cout << "Total tickets: " << allSoldCnt << endl;
  58.     cout << student * 100.0 / allSoldCnt << "% student tickets." << endl;
  59.     cout << standard * 100.0 / allSoldCnt << "% standard tickets." << endl;
  60.     cout << kid * 100.0 / allSoldCnt << "% kids tickets." << endl;
  61.  
  62.  
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment