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