Advertisement
Somo4k

04. TouristShop

Jun 15th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04._Tourist_Shop
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double budget = double.Parse(Console.ReadLine());
  10. string product = Console.ReadLine();
  11. int counterProduct = 0;
  12. int counterDiscount = 0;
  13. bool noMoney = false;
  14.  
  15. double price = 0;
  16.  
  17. while (product != "Stop")
  18. {
  19. double priceProduct = double.Parse(Console.ReadLine());
  20. counterProduct++;
  21. counterDiscount++;
  22.  
  23. if (counterDiscount == 3)
  24. {
  25. priceProduct /= 2;
  26. counterDiscount = 0;
  27. }
  28.  
  29. price += priceProduct;
  30.  
  31.  
  32. if (price > budget)
  33. {
  34. Console.WriteLine($"You don't have enough money!");
  35. Console.WriteLine($"You need {Math.Abs(price - budget):f2} leva!");
  36. noMoney = true;
  37. break;
  38. }
  39.  
  40.  
  41. product = Console.ReadLine();
  42. }
  43.  
  44. if (!noMoney)
  45. {
  46. Console.WriteLine($"You bought {counterProduct} products for {price:f2} leva.") ;
  47. }
  48. }
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement