svephoto

Cinema Tickets [C#]

Apr 1st, 2021 (edited)
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CinemaTickets
  4. {
  5.     public class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string movie = Console.ReadLine();
  10.  
  11.             int student = 0;
  12.             int standard = 0;
  13.             int kids = 0;
  14.            
  15.             while (movie != "Finish")
  16.             {
  17.                 int totalCount = 0;          
  18.                 int seats = int.Parse(Console.ReadLine());
  19.                 string ticketType = string.Empty;
  20.                
  21.                 while (ticketType != "End" && seats > totalCount)
  22.                 {
  23.                     ticketType = Console.ReadLine();
  24.                        
  25.                     switch(ticketType)
  26.                     {                                                              
  27.                         case "student":                    
  28.                             student++;
  29.                             totalCount++;
  30.                             break;
  31.                         case "standard":                    
  32.                             standard++;
  33.                             totalCount++;
  34.                             break;
  35.                         case "kid":
  36.                             kids++;
  37.                             totalCount++;
  38.                             break; 
  39.                     }
  40.                 }              
  41.  
  42.                 double percent = totalCount * 1.00 / seats * 100;
  43.  
  44.                 Console.WriteLine($"{movie} - {percent:f2}% full.");
  45.                        
  46.                 movie = Console.ReadLine();
  47.             }
  48.            
  49.             int totalTickets = student + standard + kids;            
  50.            
  51.             double studentPercent = student * 1.00 / totalTickets * 100;
  52.             double standardPercent = standard * 1.00 / totalTickets * 100;
  53.             double kidsPercent = kids * 1.00 / totalTickets * 100;
  54.  
  55.             Console.WriteLine($"Total tickets: {totalTickets}");
  56.             Console.WriteLine($"{studentPercent:f2}% student tickets.");
  57.             Console.WriteLine($"{standardPercent:f2}% standard tickets.");
  58.             Console.WriteLine($"{kidsPercent:f2}% kids tickets.");
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment