Advertisement
VickSuna

Untitled

Mar 31st, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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 needMoney = double.Parse(Console.ReadLine());
  10. double herMoney = double.Parse(Console.ReadLine());
  11. string command = Console.ReadLine();
  12. int days = 0;
  13.  
  14. int consecutiveSpendingDays = 0;
  15.  
  16. while (command == "spend" || command == "save")
  17. {
  18. double currentMoney = double.Parse(Console.ReadLine());
  19. days++;
  20. if (command == "spend")
  21. {
  22. consecutiveSpendingDays++;
  23.  
  24. herMoney -= currentMoney;
  25. if (currentMoney > herMoney)
  26. {
  27. herMoney = 0;
  28. }
  29. if (consecutiveSpendingDays == 5)
  30. {
  31. Console.WriteLine("You can't save the money.");
  32. Console.WriteLine($"{days}");
  33. break;
  34. }
  35. }
  36. else if (command == "save")
  37. {
  38. herMoney += currentMoney;
  39. consecutiveSpendingDays = 0;
  40. }
  41.  
  42. if (needMoney <= herMoney)
  43. {
  44. Console.WriteLine($"You saved the money for {days} days.");
  45. break;
  46. }
  47. command = Console.ReadLine();
  48.  
  49.  
  50.  
  51. }
  52. }
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement