Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Krassi_Vacation_While_LOOP
- {
- class Program
- {
- static void Main(string[] args)
- {
- double neededMoney = double.Parse(Console.ReadLine());
- double balance = double.Parse(Console.ReadLine());
- double dayCounter = 0;
- int spendCounter = 0;
- while (neededMoney > balance && dayCounter < 5)
- {
- string spendOrSave = Console.ReadLine();
- double moneyForSpendOrSave = double.Parse(Console.ReadLine());
- dayCounter++;
- if (spendOrSave == "spend")
- {
- balance -= moneyForSpendOrSave;
- spendCounter++;
- if (balance < 0)
- {
- balance = 0;
- }
- }
- else if (spendOrSave == "save")
- {
- balance += moneyForSpendOrSave;
- spendCounter = 0;
- }
- }
- if (dayCounter == 5)
- {
- Console.WriteLine($"You can't save the money.");
- Console.WriteLine($"{spendCounter}");
- // break;
- }
- if (balance >= neededMoney)
- {
- Console.WriteLine($"You saved the money for {dayCounter} days.");
- // break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement