Aliendreamer

vacation

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