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 budget = double.Parse(Console.ReadLine());
- int saveDays = 0, spendDays = 0;
- while (budget < moneyNeeded && spendDays < 5)
- {
- string command = Console.ReadLine();
- double money = double.Parse(Console.ReadLine());
- if (command == "spend")
- {
- spendDays++;
- if (money >= budget)
- {
- budget = 0;
- }
- else
- {
- budget -= money;
- }
- }
- else
- {
- budget += money;
- spendDays = 0;
- }
- saveDays++;
- }
- if (budget >= moneyNeeded)
- {
- Console.WriteLine($"You saved the money for {saveDays} days.");
- }
- else
- {
- Console.WriteLine($"You can't save the money.\n{saveDays}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement