nikolayneykov

Untitled

Oct 11th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 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 _04.Vacation
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double moneyExcursion = double.Parse(Console.ReadLine());
  14.             double moneyAvailable = double.Parse(Console.ReadLine());
  15.             int countSpend = 0;
  16.             int countAll = 0;
  17.  
  18.             while (true)
  19.             {
  20.                 string actionType = Console.ReadLine().ToLower();
  21.                 double actionMoney = double.Parse(Console.ReadLine());
  22.                 countAll++;
  23.                 if (actionType == "spend")
  24.                 {
  25.                     moneyAvailable -= actionMoney;
  26.                     countSpend++;
  27.                 }
  28.                 if (moneyAvailable < 0)
  29.                 {
  30.                     moneyAvailable = 0;
  31.                 }
  32.                 if (countSpend == 5)
  33.                 {
  34.                     Console.WriteLine("You can't save the money.");
  35.                     Console.WriteLine($"{countAll}");
  36.                     break;
  37.                 }
  38.                 if (actionType == "save")
  39.                 {
  40.                     moneyAvailable += actionMoney;
  41.                     countSpend = 0;
  42.                 }
  43.                 if (moneyAvailable >= moneyExcursion)
  44.                 {
  45.                     Console.WriteLine($"You saved the money for {countAll} days.");
  46.                     break;
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment