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 Vacation_1._0
- {
- class Program
- {
- static void Main(string[] args)
- {
- double neededMoney = double.Parse(Console.ReadLine());
- double balance = double.Parse(Console.ReadLine());
- double dayCounter = 0;
- while (neededMoney>=balance)
- {
- string spendOrSave = Console.ReadLine();
- double moneyForSpendOrSave = double.Parse(Console.ReadLine());
- dayCounter++;
- if (spendOrSave=="spend")
- {
- balance -= moneyForSpendOrSave;
- if (balance<=0)
- {
- balance = 0;
- }
- if (dayCounter==5)
- {
- Console.WriteLine($"You can't save the money.");
- Console.WriteLine($"{dayCounter}");
- break;
- }
- }
- else if (spendOrSave=="save")
- {
- balance += moneyForSpendOrSave;
- }
- if (balance==neededMoney)
- {
- Console.WriteLine($"You saved the money for {dayCounter} days.");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement