Advertisement
NelIfandieva

Exercise06_P06_CinemaTickets

Apr 3rd, 2022
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P06_CinemaTickets
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int studentTicketsSold = 0;
  10.             int standardTicketsSold = 0;
  11.             int kidTicketsSold = 0;
  12.  
  13.             int totalTicketsSold = 0;
  14.  
  15.             string input = "";
  16.  
  17.             while(input != "Finish")
  18.             {
  19.                 input = Console.ReadLine();
  20.  
  21.                 if(input == "Finish")
  22.                 {
  23.                     break;
  24.                 }
  25.  
  26.                 string filmTitle = input;
  27.  
  28.                 int seatsAvailable = int.Parse(Console.ReadLine());
  29.  
  30.                 int ticketsSoldForFilm = 0;
  31.  
  32.                 while (ticketsSoldForFilm < seatsAvailable)
  33.                 {
  34.                     string ticketType = Console.ReadLine();
  35.  
  36.                     if (ticketType == "End")
  37.                     {
  38.                         break;
  39.                     }
  40.  
  41.                     ticketsSoldForFilm++;
  42.                     totalTicketsSold++;
  43.  
  44.                     if (ticketType == "student")
  45.                     {
  46.                         studentTicketsSold++;
  47.                     }
  48.                     else if (ticketType == "standard")
  49.                     {
  50.                         standardTicketsSold++;
  51.                     }
  52.                     else if (ticketType == "kid")
  53.                     {
  54.                         kidTicketsSold++;
  55.                     }
  56.                 }
  57.  
  58.                 double percFull = ticketsSoldForFilm / (seatsAvailable * 1.00) * 100;
  59.                 Console.WriteLine($"{filmTitle} - {percFull:f2}% full.");
  60.             }
  61.  
  62.             Console.WriteLine($"Total tickets: {totalTicketsSold}");
  63.  
  64.             double percStudentTickets = studentTicketsSold / (totalTicketsSold * 1.00) * 100;
  65.             double percStandardTickets = standardTicketsSold / (totalTicketsSold * 1.00) * 100;
  66.             double percKidTickets = kidTicketsSold / (totalTicketsSold * 1.00) * 100;
  67.  
  68.             Console.WriteLine($"{percStudentTickets:f2}% student tickets.");
  69.             Console.WriteLine($"{percStandardTickets:f2}% standard tickets.");
  70.             Console.WriteLine($"{percKidTickets:f2}% kids tickets.");
  71.         }
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement