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 moneyNeeded = double.Parse(Console.ReadLine());
- double balance = double.Parse(Console.ReadLine());
- string input = String.Empty;
- double moneyToday = 0;
- int daysCounter = 0;
- int spendCounter = 0;
- bool Enough = false;
- while (balance < moneyNeeded && spendCounter < 5)
- {
- input = Console.ReadLine();
- moneyToday = double.Parse(Console.ReadLine());
- daysCounter++;
- if (input == "spend")
- {
- if (moneyToday >= balance)
- {
- balance = 0;
- }
- else
- {
- balance -= moneyToday;
- }
- spendCounter++;
- }
- else if (input == "save")
- {
- balance += moneyToday;
- if (balance >= moneyNeeded)
- {
- Enough = true;
- break;
- }
- spendCounter = 0;
- }
- }
- if (Enough)
- {
- Console.WriteLine($"You saved the money for {daysCounter} days.");
- }
- else if (spendCounter == 5)
- {
- Console.WriteLine("You can't save the money.");
- Console.WriteLine($"{daysCounter}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement