Advertisement
nikolayneykov

Untitled

Oct 9th, 2018
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace cake
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double moneyForExcurtion = double.Parse(Console.ReadLine());
  14.             double availableMoney = double.Parse(Console.ReadLine());
  15.  
  16.             string action = string.Empty;
  17.             double moneyForAction = 0;
  18.             int days = 0;
  19.             int daysSpent = 0;
  20.             string result = string.Empty;
  21.  
  22.  
  23.             while (true)
  24.             {
  25.                 action = Console.ReadLine();
  26.                 moneyForAction = double.Parse(Console.ReadLine());
  27.                 days++;
  28.  
  29.                 if (action == "save")
  30.                 {
  31.                     daysSpent = 0;
  32.                     availableMoney += moneyForAction;
  33.                     if (availableMoney >= moneyForExcurtion)
  34.                     {
  35.                         result = $"You saved the money for {days} days.";
  36.                         break;
  37.                     }
  38.                 }
  39.                
  40.                 if (action == "spend")
  41.                 {
  42.                     availableMoney -= moneyForAction;
  43.  
  44.                     if (availableMoney < 0)
  45.                     {
  46.                         availableMoney = 0;
  47.                     }
  48.  
  49.                     daysSpent++;
  50.  
  51.  
  52.                     if (daysSpent == 5)
  53.                     {
  54.                         result = "You can't save the money." + Environment.NewLine + $"{days}";
  55.                         break;
  56.                     }
  57.  
  58.                 }
  59.  
  60.             }
  61.             Console.WriteLine(result);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement