Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Vacation
- {
- class Vacation
- {
- static void Main(string[] args)
- {
- double moneyNeeded = double.Parse(Console.ReadLine());
- double moneyInPocket = double.Parse(Console.ReadLine());
- string prevAction = string.Empty;
- double counterSpend = 1.0;
- double counterDays = 0.0;
- while (moneyInPocket < moneyNeeded)
- {
- string action = Console.ReadLine();
- double amountSavedOrSpend = double.Parse(Console.ReadLine());
- if (action == "spend")
- {
- moneyInPocket = moneyInPocket - amountSavedOrSpend;
- if (moneyInPocket <= 0)
- {
- moneyInPocket = 0;
- }
- }
- if (action == "save")
- {
- moneyInPocket = moneyInPocket + amountSavedOrSpend;
- }
- if (prevAction == "spend")
- {
- counterSpend++;
- }
- counterDays++;
- if (counterSpend == 5.0)
- {
- Console.WriteLine("You can`t save the money.");
- Console.WriteLine($"{counterDays}");
- }
- prevAction = action;
- }
- Console.WriteLine($"You saved the money for {counterDays} days.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement