Advertisement
bokoto83

Vacation

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