Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace vacation
- {
- class Program
- {
- static void Main(string[] args)
- {
- double needMoney = double.Parse(Console.ReadLine());
- double herMoney = double.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- int days = 0;
- int consecutiveSpendingDays = 0;
- while (command == "spend" || command == "save")
- {
- double currentMoney = double.Parse(Console.ReadLine());
- days++;
- if (command == "spend")
- {
- consecutiveSpendingDays++;
- herMoney -= currentMoney;
- if (currentMoney > herMoney)
- {
- herMoney = 0;
- }
- if (consecutiveSpendingDays == 5)
- {
- Console.WriteLine("You can't save the money.");
- Console.WriteLine($"{days}");
- break;
- }
- }
- else if (command == "save")
- {
- herMoney += currentMoney;
- consecutiveSpendingDays = 0;
- }
- if (needMoney <= herMoney)
- {
- Console.WriteLine($"You saved the money for {days} days.");
- break;
- }
- command = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement