Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace cake
- {
- class Program
- {
- static void Main(string[] args)
- {
- double moneyForExcurtion = double.Parse(Console.ReadLine());
- double availableMoney = double.Parse(Console.ReadLine());
- string action = string.Empty;
- double moneyForAction = 0;
- int days = 0;
- int daysSpent = 0;
- string result = string.Empty;
- while (true)
- {
- action = Console.ReadLine();
- moneyForAction = double.Parse(Console.ReadLine());
- days++;
- if (action == "save")
- {
- daysSpent = 0;
- availableMoney += moneyForAction;
- if (availableMoney >= moneyForExcurtion)
- {
- result = $"You saved the money for {days} days.";
- break;
- }
- }
- if (action == "spend")
- {
- availableMoney -= moneyForAction;
- if (availableMoney < 0)
- {
- availableMoney = 0;
- }
- daysSpent++;
- if (daysSpent == 5)
- {
- result = "You can't save the money." + Environment.NewLine + $"{days}";
- break;
- }
- }
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement