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