Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1
- {
- using System;
- public class Program
- {
- public static void Main()
- {
- double moneyForExcurtion = double.Parse(Console.ReadLine());
- double availableMoney = double.Parse(Console.ReadLine());
- int days = 0;
- int spendingDays = 0;
- string result;
- while (true)
- {
- string action = Console.ReadLine();
- double moneyForTheDay = double.Parse(Console.ReadLine());
- days++;
- switch (action)
- {
- case "spend":
- spendingDays += 1;
- availableMoney -= moneyForTheDay;
- break;
- case "save":
- spendingDays = 0;
- availableMoney += moneyForTheDay;
- break;
- default:
- continue;
- }
- if (availableMoney >= moneyForExcurtion)
- {
- result = $"You saved the money for {days} days.";
- break;
- }
- if (availableMoney <= 0)
- {
- availableMoney = 0.00;
- }
- if (spendingDays == 5)
- {
- result = "You can't save the money." + Environment.NewLine + $"{days}";
- break;
- }
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment