Advertisement
svephoto

Cinema Tickets [C#]

Aug 6th, 2021
1,669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CinemaTickets
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string movieName = Console.ReadLine();
  10.  
  11.             int totalStudentTickets = 0;
  12.             int totalStandardTickets = 0;
  13.             int totalKidsTickets = 0;
  14.  
  15.             while (movieName != "Finish")
  16.             {
  17.                 int ticketsOfCurrentMovieCount = 0;
  18.                 int freeSpacesOfCurrentMovie = int.Parse(Console.ReadLine());
  19.  
  20.                 string typeOfCurrentTicket = string.Empty;
  21.  
  22.                 while (typeOfCurrentTicket != "End" && ticketsOfCurrentMovieCount < freeSpacesOfCurrentMovie)
  23.                 {
  24.                     typeOfCurrentTicket = Console.ReadLine();
  25.  
  26.                     switch (typeOfCurrentTicket)
  27.                     {
  28.                         case "student": totalStudentTickets++; ticketsOfCurrentMovieCount++; break;
  29.                         case "standard": totalStandardTickets++; ticketsOfCurrentMovieCount++; break;
  30.                         case "kid": totalKidsTickets++; ticketsOfCurrentMovieCount++; break;
  31.                     }
  32.                 }
  33.  
  34.                 double pOccupancyOfTheHall = ticketsOfCurrentMovieCount * 1.0 / freeSpacesOfCurrentMovie * 100;
  35.  
  36.                 Console.WriteLine($"{movieName} - {pOccupancyOfTheHall:f2}% full.");
  37.  
  38.                 movieName = Console.ReadLine();
  39.             }
  40.  
  41.             int totalTickets = totalStudentTickets + totalStandardTickets + totalKidsTickets;
  42.  
  43.             double pStudentTickets = totalStudentTickets * 1.0 / totalTickets * 100;
  44.             double pStandardTickets = totalStandardTickets * 1.0 / totalTickets * 100;
  45.             double pKidsTickets = totalKidsTickets * 1.0 / totalTickets * 100;
  46.  
  47.             Console.WriteLine($"Total tickets: {totalTickets}");
  48.             Console.WriteLine($"{pStudentTickets:f2}% student tickets.");
  49.             Console.WriteLine($"{pStandardTickets:f2}% standard tickets.");
  50.             Console.WriteLine($"{pKidsTickets:f2}% kids tickets.");
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement