Advertisement
Prohause

VAcation

Oct 11th, 2018
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double moneyForExcurtion = double.Parse(Console.ReadLine());
  10. double availableMoney = double.Parse(Console.ReadLine());
  11.  
  12. string action = string.Empty;
  13. double moneyForAction = 0;
  14. int days = 0;
  15. int daysSpent = 0;
  16. string result = string.Empty;
  17.  
  18.  
  19. while (true)
  20. {
  21. action = Console.ReadLine();
  22. moneyForAction = double.Parse(Console.ReadLine());
  23. days++;
  24.  
  25. if (action == "save")
  26. {
  27. daysSpent = 0;
  28. availableMoney += moneyForAction;
  29. if (availableMoney >= moneyForExcurtion)
  30. {
  31. result = $"You saved the money for {days} days.";
  32. break;
  33. }
  34.  
  35. }
  36.  
  37. else if (action == "spend")
  38. {
  39. availableMoney -= moneyForAction;
  40.  
  41. if (availableMoney < 0)
  42. {
  43. availableMoney = 0;
  44. }
  45.  
  46. daysSpent++;
  47.  
  48.  
  49. if (daysSpent == 5)
  50. {
  51. result = "You can't save the money." + Environment.NewLine + $"{days}";
  52. break;
  53. }
  54.  
  55. }
  56.  
  57. }
  58.  
  59. Console.WriteLine(result);
  60.  
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement