Advertisement
Guest User

06. Cinema Tickets

a guest
Oct 9th, 2019
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06._Cinema_Tickets
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string movieName = "";
  10.  
  11.             int students = 0;
  12.             int standards = 0;
  13.             int kids = 0;
  14.             int totalTicketsBought = students + standards + kids;
  15.  
  16.             while ((movieName = Console.ReadLine()) != "Finish")
  17.             {
  18.                 int freeSpaces = int.Parse(Console.ReadLine());
  19.                 int ticketsBought = 0;
  20.  
  21.                 for (int i = 0; i < freeSpaces; i++)
  22.                 {
  23.                     string typeOfTicket = Console.ReadLine();
  24.                    
  25.  
  26.                     if (typeOfTicket == "End")
  27.                     {
  28.                         break;
  29.                     }
  30.                     switch (typeOfTicket)
  31.                     {
  32.                         case "student":
  33.                             students++;
  34.                             ticketsBought++;
  35.                             break;
  36.                         case "standard":
  37.                             standards++;
  38.                             ticketsBought++;
  39.                             break;
  40.                         case "kid":
  41.                             kids++;
  42.                             ticketsBought++;
  43.                             break;
  44.                     }
  45.                 }
  46.                 double percentageOccupied = (ticketsBought / freeSpaces) * 100;
  47.                
  48.  
  49.  
  50.                 Console.WriteLine($"{movieName} - {percentageOccupied:f2}% full.");
  51.             }
  52.             Console.WriteLine($"Total tickets: {totalTicketsBought}" + Environment.NewLine + $"{students / totalTicketsBought * 100}% student tickets." + Environment.NewLine + $"{standards / totalTicketsBought * 100}% standard tickets." + Environment.NewLine + $"{kids / totalTicketsBought * 100}% kids tickets.");
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement