Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double neededMoney = double.Parse(Console.ReadLine());
- double availableMoney = double.Parse(Console.ReadLine());
- int daysCounter = 0;
- int counterSpend = 0;
- while (availableMoney < neededMoney)
- {
- string command = Console.ReadLine();
- double operationalMoney = double.Parse(Console.ReadLine());
- daysCounter++;
- if (command == "spend")
- {
- counterSpend++;
- availableMoney -= operationalMoney;
- if (counterSpend == 5)
- {
- Console.WriteLine($"You can't save the money.");
- Console.WriteLine($"{daysCounter}");
- break;
- }
- if (availableMoney < 0)
- {
- availableMoney = 0;
- }
- }
- else if (command == "save")
- {
- availableMoney += operationalMoney;
- }
- }
- if (availableMoney >= neededMoney)
- {
- Console.WriteLine($"You saved the money for {daysCounter} days.");
- }
Advertisement
Add Comment
Please, Sign In to add comment