Advertisement
aggressiveviking

Untitled

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