Advertisement
Guest User

CinemaVoucher

a guest
Apr 12th, 2019
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CinemaVoucher
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int voucherValue = int.Parse(Console.ReadLine());
  14.             int moviePrice = 0;
  15.             int productPrice = 0;
  16.             int purchasedProducts = 0;
  17.             int purchasedTickets = 0;
  18.             while (voucherValue >= 0)
  19.             {
  20.                 string purchase = Console.ReadLine();
  21.                 if (purchase == "End")
  22.                 {
  23.                     Console.WriteLine($"{purchasedTickets}");
  24.                     Console.WriteLine($"{purchasedProducts}");
  25.                     break;
  26.                 }
  27.                 if (purchase.Length > 8)
  28.                 {
  29.                     moviePrice = purchase[0] + purchase[1];
  30.                     voucherValue -= moviePrice;
  31.                     purchasedTickets++;
  32.                     if (voucherValue < moviePrice)
  33.                     {
  34.                         Console.WriteLine($"{purchasedTickets}");
  35.                         Console.WriteLine($"{purchasedProducts}");
  36.                         break;
  37.                     }
  38.                 }
  39.                 else if(purchase.Length <= 8)
  40.                 {
  41.                     productPrice = purchase[0];
  42.                     voucherValue -= productPrice;
  43.                     purchasedProducts++;
  44.                     if (voucherValue < productPrice)
  45.                     {
  46.                         Console.WriteLine($"{purchasedTickets}");
  47.                         Console.WriteLine($"{purchasedProducts}");
  48.                         break;
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement