Advertisement
SvetlanPetrova

CinemaTickets

Apr 8th, 2019 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 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 = string.Empty;
  10.             int spareSeats = 0;
  11.             string ticketType = string.Empty;
  12.             int countStudent = 0;
  13.             int countStandard = 0;
  14.             int countKid = 0;
  15.             int sumTicketsPerMovie = 0;
  16.             int sumTotalStudentTickets = 0;
  17.             int sumTotalStandardTickets = 0;
  18.             int sumTotalKidTickets = 0;
  19.            
  20.             while (movieName != "Finish")
  21.             {
  22.                 sumTicketsPerMovie = 0;
  23.                 countStudent = 0;
  24.                 countStandard = 0;
  25.                 countKid = 0;
  26.                 ticketType = string.Empty;
  27.                 movieName = Console.ReadLine();
  28.  
  29.                 if (movieName == "Finish")
  30.                 {
  31.                     break;
  32.                 }
  33.  
  34.                 spareSeats = int.Parse(Console.ReadLine());
  35.  
  36.                 while (ticketType != "End")
  37.                 {
  38.                     ticketType = Console.ReadLine();
  39.  
  40.                     if (ticketType == "End")
  41.                     {
  42.                         break;
  43.                     }
  44.                    
  45.                     if (ticketType == "student")
  46.                     {
  47.                         countStudent++;
  48.                         sumTotalStudentTickets++;
  49.  
  50.                     }
  51.                     else if (ticketType == "standard")
  52.                     {
  53.                         countStandard++;
  54.                         sumTotalStandardTickets++;
  55.                     }
  56.                     else if (ticketType == "kid")
  57.                     {
  58.                         countKid++;
  59.                         sumTotalKidTickets++;
  60.  
  61.                     }
  62.  
  63.                     sumTicketsPerMovie = countStudent + countStandard + countKid;
  64.                     if (sumTicketsPerMovie >= spareSeats)
  65.                     {
  66.                         break;
  67.                     }
  68.                 }
  69.  
  70.                 Console.WriteLine($"{movieName} - {(sumTicketsPerMovie * 1.0 * 100 / spareSeats):f2}% full.");
  71.             }
  72.  
  73.             int sumTotalTickets = sumTotalStudentTickets + sumTotalStandardTickets + sumTotalKidTickets;
  74.  
  75.             double procentageStudent = sumTotalStudentTickets * 1.0 * 100 / sumTotalTickets;
  76.             double procentageStandard = sumTotalStandardTickets * 1.0 * 100 / sumTotalTickets;
  77.             double procentageKid = sumTotalKidTickets * 1.0 * 100 / sumTotalTickets;
  78.  
  79.             Console.WriteLine($"Total tickets: {sumTotalTickets}");
  80.             Console.WriteLine($"{procentageStudent:f2}% student tickets.");
  81.             Console.WriteLine($"{procentageStandard:f2}% standard tickets.");
  82.             Console.WriteLine($"{procentageKid:f2}% kids tickets.");
  83.  
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement