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