Advertisement
Grimmjow1

Vacation2

Feb 8th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 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 Vacation2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double moneyForVacation = double.Parse(Console.ReadLine());
  14.             double ownMoney = double.Parse(Console.ReadLine());
  15.  
  16.             string action = string.Empty;
  17.             double money = 0;
  18.             int days = 0;
  19.             int daysSpend = 0;
  20.             string result = string.Empty;
  21.  
  22.             while (true)
  23.             {
  24.                 action = Console.ReadLine();
  25.                 money = double.Parse(Console.ReadLine());
  26.                 days++;
  27.                 if (action=="save")
  28.                 {
  29.                     daysSpend = 0;
  30.                     ownMoney += money;
  31.                     if (ownMoney>=moneyForVacation)
  32.                     {
  33.                         result = $"You saved the money for {days} days.";
  34.                         break;
  35.                     }
  36.                 }
  37.                 if (action=="spend")
  38.                 {
  39.                     daysSpend++;
  40.                     ownMoney -= money;
  41.                     if (ownMoney < 0)
  42.                     {
  43.                         ownMoney = 0;
  44.  
  45.                     }
  46.                     if (daysSpend==5)
  47.                     {
  48.                         result = "You can't save the money." + Environment.NewLine + $"{days}";
  49.                         break;
  50.                     }
  51.                 }
  52.  
  53.  
  54.             }
  55.             Console.WriteLine(result);
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement