Advertisement
svephoto

Vacation

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