Advertisement
sanyakasarova

03. Vacation

Jun 6th, 2021
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _2._Exam_Preparation
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double moneyNeeded = double.Parse(Console.ReadLine());
  10. double savedMoney = double.Parse(Console.ReadLine());
  11.  
  12. int spendDaysCounter = 0;
  13. int daysCounter = 0;
  14.  
  15. while (savedMoney < moneyNeeded)
  16. {
  17. string action = Console.ReadLine();
  18. double amount = double.Parse(Console.ReadLine());
  19.  
  20. daysCounter++;
  21.  
  22. if (action == "spend")
  23. {
  24. spendDaysCounter++;
  25. savedMoney -= amount;
  26.  
  27. if (savedMoney < 0)
  28. {
  29. savedMoney = 0;
  30. }
  31. }
  32. else if (action == "save")
  33. {
  34. spendDaysCounter = 0;
  35. savedMoney += amount;
  36. }
  37.  
  38. if (spendDaysCounter == 5)
  39. {
  40. Console.WriteLine("You can't save the money.");
  41. Console.WriteLine($"{daysCounter}");
  42. break;
  43. }
  44. }
  45.  
  46. if (savedMoney >= moneyNeeded)
  47. {
  48. Console.WriteLine($"You saved the money for {daysCounter} days.");
  49. }
  50.  
  51.  
  52. }
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement