Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CinemaVoucher
- {
- class Program
- {
- static void Main(string[] args)
- {
- int voucherValue = int.Parse(Console.ReadLine());
- string purchase = string.Empty;
- int price = 0;
- int currentCost = 0;
- int valueLeft = 0;
- int ticketsBought = 0;
- int otherPurchases = 0;
- while (purchase != "End")
- {
- valueLeft = voucherValue - currentCost;
- purchase = Console.ReadLine();
- if (purchase == "End")
- {
- break;
- }
- if (purchase.Length > 8)
- {
- price = purchase[0] + purchase[1];
- if (price > valueLeft)
- {
- break;
- }
- else
- {
- ticketsBought++;
- }
- }
- else if (purchase.Length <= 8)
- {
- price = purchase[0];
- if (price > valueLeft)
- {
- break;
- }
- else
- {
- otherPurchases++;
- }
- }
- if (price > valueLeft)
- {
- break;
- }
- currentCost += price;
- }
- Console.WriteLine($"{ticketsBought}");
- Console.WriteLine($"{otherPurchases}");
- }
- }
- }
Add Comment
Please, Sign In to add comment