Advertisement
spasnikolov131

Untitled

Apr 25th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 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 ownedMoney = double.Parse(Console.ReadLine());
  11. int days = 0; // броя изминали дни
  12. int daysSpend = 0; // броя последователни дни
  13.  
  14. double spendedMoney = double.Parse(Console.ReadLine());
  15. while (ownedMoney < neededMoney && daysSpend < 5)
  16. {
  17. string command = Console.ReadLine();
  18. double money = double.Parse(Console.ReadLine());
  19. days++;
  20. if (command == "spend")
  21. {
  22. ownedMoney += money;
  23. if (ownedMoney < 0)
  24. {
  25. ownedMoney = 0;
  26. }
  27. daysSpend++;
  28. if (daysSpend >= 5)
  29. {
  30. break;
  31. }
  32. }
  33. else if (command == "save")
  34. {
  35. ownedMoney += money;
  36. daysSpend = 0;
  37. }
  38. }
  39. if (daysSpend == 5)
  40. {
  41. Console.WriteLine("You can't save the money.");
  42. Console.WriteLine(daysSpend);
  43. }
  44. if (ownedMoney >= neededMoney)
  45. {
  46. Console.WriteLine($"You saved the money for {daysSpend} days.");
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement