SvetlanPetrova

Cinema Voucher SoftUni

Apr 8th, 2019 (edited)
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CinemaVoucher
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int voucherValue = int.Parse(Console.ReadLine());
  10.  
  11.             string purchase = string.Empty;
  12.  
  13.             int price = 0;
  14.             int currentCost = 0;
  15.             int valueLeft = 0;
  16.             int ticketsBought = 0;
  17.             int otherPurchases = 0;
  18.  
  19.             while (purchase != "End")
  20.             {
  21.                 valueLeft = voucherValue - currentCost;
  22.                 purchase = Console.ReadLine();
  23.                 if (purchase == "End")
  24.                 {
  25.                     break;
  26.                 }
  27.  
  28.                 if (purchase.Length > 8)
  29.                 {
  30.                     price = purchase[0] + purchase[1];
  31.                     if (price > valueLeft)
  32.                     {
  33.                         break;
  34.                     }
  35.                     else
  36.                     {
  37.                         ticketsBought++;
  38.                     }
  39.                    
  40.                 }
  41.  
  42.                 else if (purchase.Length <= 8)
  43.                 {
  44.                     price = purchase[0];
  45.                     if (price > valueLeft)
  46.                     {
  47.                         break;
  48.                     }
  49.                     else
  50.                     {
  51.                         otherPurchases++;
  52.                     }
  53.                    
  54.                 }
  55.  
  56.                 if (price > valueLeft)
  57.                 {
  58.                     break;
  59.                 }
  60.  
  61.                 currentCost += price;
  62.                
  63.             }
  64.  
  65.             Console.WriteLine($"{ticketsBought}");
  66.             Console.WriteLine($"{otherPurchases}");
  67.         }
  68.     }
  69. }
Add Comment
Please, Sign In to add comment