Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04Vacantion
- {
- class Program
- {
- static void Main(string[] args)
- {
- double needMoneyForExcursion = double.Parse(Console.ReadLine());
- double money = double.Parse(Console.ReadLine());
- double daysCounter = 0;
- double spendCounter = 0;
- string input = "";
- double sumMoney = money;
- do
- {
- if (spendCounter == 5)
- {
- break;
- }
- else
- {
- input = Console.ReadLine();
- money = double.Parse(Console.ReadLine());
- if (input == "save")
- {
- sumMoney = sumMoney + money;
- spendCounter = 0;
- }
- else if (input == "spend")
- {
- if (money >= sumMoney)
- {
- sumMoney = 0;
- }
- else
- {
- sumMoney = sumMoney - money;
- }
- spendCounter++;
- }
- daysCounter++;
- }
- } while (sumMoney < needMoneyForExcursion);
- if (sumMoney >= needMoneyForExcursion)
- {
- Console.WriteLine($"You saved the money for {daysCounter} days.");
- }
- if (spendCounter == 5)
- {
- Console.WriteLine($"You can't save the money.");
- Console.WriteLine(daysCounter);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement