Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.34 KB | None | 0 0
  1. using System;
  2.  
  3. namespace labexercise
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Travelling();
  10.             //CinemaTickets();
  11.         }
  12.         public static void Travelling()
  13.         {
  14.             string destination = Console.ReadLine();
  15.             double budget = double.Parse(Console.ReadLine());
  16.             double neededMoney = 0;
  17.  
  18.             while (destination != "End")
  19.             {
  20.                 while (neededMoney < budget)
  21.                 {
  22.                     double savedMoney = double.Parse(Console.ReadLine());
  23.                     neededMoney += savedMoney;
  24.                     if (neededMoney >= budget)
  25.                     {
  26.                         Console.WriteLine($"Going to {destination}!"); ;
  27.                         neededMoney = 0;
  28.                         break;
  29.                     }
  30.                 }
  31.                 destination = Console.ReadLine();
  32.                 if (destination != "End")
  33.                 {
  34.                     budget = double.Parse(Console.ReadLine());
  35.                 }
  36.             }
  37.  
  38.         }
  39.         public static void CinemaTickets()
  40.         {
  41.             string input = Console.ReadLine();
  42.             int studentCounter = 0;
  43.             int standardCounter = 0;
  44.             int kidsCounter = 0;
  45.             int totalTickets = 0;
  46.             int totalKidsCounter = 0;
  47.             int totalStadardCounter = 0;
  48.             int totalStudentCounter = 0;
  49.  
  50.             while (input != "Finish")
  51.             {
  52.                 int freeSeats = int.Parse(Console.ReadLine());
  53.                 for (int ticketCounter = 1; ticketCounter <= freeSeats; ticketCounter++)
  54.                 {
  55.                     string typeOfTicket = Console.ReadLine();
  56.                     switch (typeOfTicket)
  57.                     {
  58.                         case "student": studentCounter++; totalStudentCounter++; break;
  59.                         case "standard": standardCounter++; totalStadardCounter++; break;
  60.                         case "kid": kidsCounter++; totalKidsCounter++; break;
  61.                         default:
  62.                             break;
  63.                     }
  64.                     if (typeOfTicket == "End")
  65.                     {
  66.                         break;
  67.                     }
  68.                     totalTickets++;
  69.                 }
  70.                 if (freeSeats > (studentCounter + standardCounter + kidsCounter))
  71.                 {
  72.                     Console.WriteLine($"{input} - {((100.00 / freeSeats) * (studentCounter + standardCounter + kidsCounter)):F2}% full.");
  73.                 }
  74.                 else if (freeSeats == (studentCounter + standardCounter + kidsCounter))
  75.                 {
  76.                     Console.WriteLine($"{input} - 100.00% full.");
  77.                 }
  78.  
  79.                 studentCounter = 0;
  80.                 standardCounter = 0;
  81.                 kidsCounter = 0;
  82.                 input = Console.ReadLine();
  83.             }
  84.             Console.WriteLine($"Total tickets: {totalTickets}");
  85.             Console.WriteLine($"{((100.00 / totalTickets) * totalStudentCounter):F2}% student tickets.");
  86.             Console.WriteLine($"{((100.00 / totalTickets) * totalStadardCounter):F2}% standard tickets.");
  87.             Console.WriteLine($"{((100.00 / totalTickets) * totalKidsCounter):F2}% kids tickets.");
  88.  
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement