Advertisement
slibchev

Cinema Voucher

Oct 22nd, 2023
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | Source Code | 0 0
  1. double voucherValue = double.Parse(Console.ReadLine());
  2.  
  3. string purchase = Console.ReadLine();
  4. int ticketsCount = 0;
  5. int purchaseCount = 0;
  6. bool noMoreMoney = false;
  7.  
  8. while (purchase != "End")
  9. {
  10.  
  11. double movieTicketPrice = 0;
  12. double otherPurchasePrice = 0;
  13.  
  14. for (int i = 0; i < purchase.Length; i++)
  15. {
  16.  
  17. char letter = purchase[i];
  18.  
  19. if (purchase.Length > 8)
  20. {
  21. if (i == 0 || i == 1)
  22. {
  23. movieTicketPrice += letter;
  24.  
  25. }
  26. else
  27. {
  28. ticketsCount++;
  29. break;
  30. }
  31.  
  32. }
  33. else if (purchase.Length <= 8)
  34. {
  35. if ( i == 0)
  36. {
  37. otherPurchasePrice += letter;
  38.  
  39. if (voucherValue < otherPurchasePrice)
  40. {
  41. noMoreMoney = true;
  42. break;
  43. }
  44. purchaseCount++;
  45. break;
  46. }
  47.  
  48. }
  49.  
  50.  
  51. }
  52. if (noMoreMoney)
  53. {
  54. break;
  55. }
  56. voucherValue -= movieTicketPrice;
  57. voucherValue -= otherPurchasePrice;
  58.  
  59. purchase = Console.ReadLine();
  60. }
  61.  
  62. Console.WriteLine($"{ticketsCount}");
  63. Console.WriteLine($"{purchaseCount}");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement