SHARE
TWEET

Vacation

trichkov May 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace Vacation
  4. {
  5.     class Vacation
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double moneyNeeded = double.Parse(Console.ReadLine());
  10.             double moneyInPocket = double.Parse(Console.ReadLine());
  11.             string prevAction = string.Empty;
  12.             double counterSpend = 1.0;
  13.             double counterDays = 0.0;
  14.             while (moneyInPocket < moneyNeeded)
  15.             {
  16.                 string action = Console.ReadLine();
  17.                 double amountSavedOrSpend = double.Parse(Console.ReadLine());
  18.                 if (action == "spend")
  19.                 {
  20.                    
  21.                     moneyInPocket = moneyInPocket - amountSavedOrSpend;
  22.                     if (moneyInPocket <= 0)
  23.                     {
  24.                         moneyInPocket = 0;
  25.                     }
  26.                 }
  27.                 if (action == "save")
  28.                 {
  29.                     moneyInPocket = moneyInPocket + amountSavedOrSpend;
  30.                 }
  31.                 if (prevAction == "spend")
  32.                 {
  33.                     counterSpend++;
  34.                 }
  35.                 counterDays++;
  36.                 if (counterSpend == 5.0)
  37.                 {
  38.                     Console.WriteLine("You can`t save the money.");
  39.                     Console.WriteLine($"{counterDays}");
  40.                 }
  41.                 prevAction = action;
  42.             }
  43.             Console.WriteLine($"You saved the money for {counterDays} days.");
  44.         }
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top