svephoto

Cinema Tickets [C#]

Feb 13th, 2022 (edited)
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.01 KB | None | 0 0
  1. using System;
  2. //using System.Linq;
  3. //using System.Collections.Generic;
  4.  
  5. namespace Cinema_Tickets
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string movie = Console.ReadLine();
  12.  
  13.             double counterStandard = 0;
  14.             double counterStuden = 0;
  15.             double counterKid = 0;
  16.             double procent = 0;
  17.             double sum = 0;
  18.             //double counterTickets = 1;
  19.             double counterTickets = 0; // Трябва да започнем с начална стойност 0.
  20.             double freeSpaces = 0;
  21.  
  22.             double counterStandard2 = 0;
  23.             double counterStuden2 = 0;
  24.             double counterKid2 = 0;
  25.  
  26.             while (movie != "Finish")
  27.             {
  28.                 freeSpaces = int.Parse(Console.ReadLine());
  29.                 string type = Console.ReadLine();
  30.  
  31.                 while (type != "End")
  32.                 {
  33.                     if (type == "standard")
  34.                     {
  35.                         counterStandard++;
  36.                         counterStandard2++;
  37.                     }
  38.                     else if (type == "student")
  39.                     {
  40.                         counterStuden++;
  41.                         counterStuden2++;
  42.                     }
  43.                     else if (type == "kid")
  44.                     {
  45.                         counterKid++;
  46.                         counterKid2++;
  47.                     }
  48.  
  49.                     sum = counterStandard + counterKid + counterStuden;
  50.                     counterTickets++; // Трябва да увеличаваме брояча тук, понеже ако е след if-проверката с break-a, няма да можем да добавим още един билет.
  51.  
  52.                     if (sum >= freeSpaces)
  53.                     {
  54.                         break;
  55.                     }
  56.  
  57.                     type = Console.ReadLine();                    
  58.                 }
  59.  
  60.                 procent = 100 * sum / freeSpaces;
  61.  
  62.                 Console.WriteLine($"{movie} - {procent:f2}% full.");
  63.  
  64.                 counterStandard = 0;
  65.                 counterStuden = 0;
  66.                 counterKid = 0;
  67.                 sum = 0;
  68.  
  69.                 movie = Console.ReadLine();
  70.             }
  71.  
  72.             //sum = counterStandard + counterKid + counterStuden; - Не виждам за какво са тези сметки тук, след като никъде не се използват.
  73.             //procent = 100 * sum / freeSpaces;
  74.  
  75.             double studProz = 100 * counterStuden2 / counterTickets;
  76.             double sandProz = 100 * counterStandard2 / counterTickets;
  77.             double kidProz = 100 * counterKid2 / counterTickets;        
  78.  
  79.             Console.WriteLine($"Total tickets: {counterTickets}");
  80.             Console.WriteLine($"{studProz:f2}% student tickets.");
  81.             Console.WriteLine($"{sandProz:f2}% standard tickets.");
  82.             Console.WriteLine($"{kidProz:f2}% kids tickets.");
  83.         }
  84.     }
  85. }
  86.  
Add Comment
Please, Sign In to add comment