angelllo

Untitled

Mar 10th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. double neededMoney = double.Parse(Console.ReadLine());
  2. double availableMoney = double.Parse(Console.ReadLine());
  3. int daysCounter = 0;
  4. int counterSpend = 0;
  5.  
  6. while (availableMoney < neededMoney)
  7. {
  8. string command = Console.ReadLine();
  9. double operationalMoney = double.Parse(Console.ReadLine());
  10. daysCounter++;
  11.  
  12. if (command == "spend")
  13. {
  14. counterSpend++;
  15. availableMoney -= operationalMoney;
  16. if (counterSpend == 5)
  17. {
  18. Console.WriteLine($"You can't save the money.");
  19. Console.WriteLine($"{daysCounter}");
  20. break;
  21. }
  22.  
  23. if (availableMoney < 0)
  24. {
  25. availableMoney = 0;
  26. }
  27. }
  28. else if (command == "save")
  29. {
  30. availableMoney += operationalMoney;
  31. }
  32. }
  33. if (availableMoney >= neededMoney)
  34. {
  35. Console.WriteLine($"You saved the money for {daysCounter} days.");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment