Advertisement
Guest User

Zadacha4

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