Advertisement
alexbancheva

Krassy_Jessy's_Vacation

Feb 10th, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Krassi_Vacation_While_LOOP
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double neededMoney = double.Parse(Console.ReadLine());
  10.             double balance = double.Parse(Console.ReadLine());
  11.             double dayCounter = 0;
  12.             int spendCounter = 0;
  13.  
  14.  
  15.             while (neededMoney > balance && dayCounter < 5)
  16.             {
  17.                 string spendOrSave = Console.ReadLine();
  18.                 double moneyForSpendOrSave = double.Parse(Console.ReadLine());
  19.  
  20.                 dayCounter++;
  21.  
  22.                 if (spendOrSave == "spend")
  23.                 {
  24.                     balance -= moneyForSpendOrSave;
  25.                     spendCounter++;
  26.  
  27.                     if (balance < 0)
  28.                     {
  29.                         balance = 0;
  30.                     }
  31.                    
  32.                 }
  33.                 else if (spendOrSave == "save")
  34.                 {
  35.                     balance += moneyForSpendOrSave;
  36.                     spendCounter = 0;
  37.                 }
  38.  
  39.             }
  40.  
  41.             if (dayCounter == 5)
  42.             {
  43.                 Console.WriteLine($"You can't save the money.");
  44.                 Console.WriteLine($"{spendCounter}");
  45.               //  break;
  46.             }
  47.             if (balance >= neededMoney)
  48.             {
  49.                 Console.WriteLine($"You saved the money for {dayCounter} days.");
  50.               //  break;
  51.             }
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement