SHARE
TWEET

Untitled

desislavg May 18th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace Vacation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double needMoneyForTrip = double.Parse(Console.ReadLine());
  10.             double ownedMoney = double.Parse(Console.ReadLine());
  11.             int spendCounter = 0;
  12.             int countAllDays = 0;
  13.  
  14.  
  15.             while (ownedMoney < needMoneyForTrip && spendCounter < 5)
  16.             {
  17.                 string action = Console.ReadLine();
  18.                 double money = double.Parse(Console.ReadLine());
  19.                 countAllDays++;
  20.  
  21.                 if (action == "save")
  22.                 {
  23.                     ownedMoney += money;
  24.                     spendCounter = 0;
  25.                 }
  26.  
  27.                 if (action == "spend")
  28.                 {
  29.                     ownedMoney -= money;
  30.                     spendCounter++;
  31.  
  32.                     if (ownedMoney < 0)
  33.                     {
  34.                         ownedMoney = 0;
  35.                     }
  36.                 }
  37.                 if (spendCounter == 5)
  38.                 {
  39.                         Console.WriteLine("You can't save the money.");
  40.                         Console.WriteLine(countAllDays);
  41.                         break;  
  42.                 }
  43.                 if (ownedMoney >= needMoneyForTrip)
  44.                 {
  45.                     Console.WriteLine($"You saved the money for {countAllDays} days.");
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
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