Advertisement
nnikolov

Untitled

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