Advertisement
Grimmjow1

Vacation

Feb 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 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 moneyNeeded = double.Parse(Console.ReadLine());
  10.             double ownMoney = double.Parse(Console.ReadLine());
  11.             int daysCouter = 0;
  12.             int spendCounter = 0;
  13.  
  14.  
  15.  
  16.             while (ownMoney<moneyNeeded)
  17.             {
  18.                 string action = Console.ReadLine();
  19.                 double money = double.Parse(Console.ReadLine());
  20.                 daysCouter++;
  21.                 if (action=="save")
  22.                 {
  23.                     ownMoney += money;
  24.                     spendCounter = 0;
  25.                 }
  26.                 else if (action=="spend")
  27.                 {
  28.                     spendCounter++;
  29.                     ownMoney -= money;
  30.                     if (ownMoney<0)
  31.                     {
  32.                         ownMoney = 0;
  33.                     }
  34.                     if (spendCounter==5)
  35.                     {
  36.                         Console.WriteLine("You can't save the money.");
  37.                         Console.WriteLine(daysCouter);
  38.                         break;
  39.                     }
  40.  
  41.                 }
  42.                  
  43.                
  44.             }
  45.             if (spendCounter<5)
  46.             {
  47.                 Console.WriteLine($"You saved the money for {daysCouter} days.");
  48.             }
  49.            
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement