Advertisement
jkonova

Untitled

Aug 2nd, 2021
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Vacation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double moneyForExcursion = double.Parse(Console.ReadLine());
  10.             double moneyOnHand = double.Parse(Console.ReadLine());
  11.  
  12.             int daysForSpending = 0;
  13.             int daysCount = 0;
  14.  
  15.             while (moneyOnHand < moneyForExcursion)
  16.             {
  17.                 string actionType = Console.ReadLine();
  18.                 double amount = double.Parse(Console.ReadLine());
  19.  
  20.                 daysCount++;
  21.  
  22.                 switch (actionType)
  23.                 {
  24.                     case "spend":
  25.                         if (amount > moneyOnHand)
  26.                         {
  27.                             moneyOnHand = 0;
  28.                         }
  29.                         else
  30.                         {
  31.                             moneyOnHand -= amount;
  32.                         } daysForSpending++; break;
  33.                     case "save": moneyOnHand += amount; daysForSpending = 0; break;
  34.                 }
  35.                 if (daysForSpending == 5)
  36.                 {
  37.                     Console.WriteLine("You can't save the money.");
  38.                     Console.WriteLine(daysForSpending); break;
  39.                 }
  40.             }
  41.             if (moneyOnHand >= moneyForExcursion)
  42.             {
  43.                 Console.WriteLine($"You saved the money for {daysCount} days.");
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement