Advertisement
DimitarTsvetkov

Vacation

Nov 8th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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 Vacation
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double moneyForVacation = double.Parse(Console.ReadLine());
  14.             double moneyAvailable = double.Parse(Console.ReadLine());
  15.  
  16.             string action = "";
  17.             double sum = 0;
  18.  
  19.             int spendCounter = 0;
  20.             int counter = 0;
  21.  
  22.             while (true)
  23.             {
  24.                 action = Console.ReadLine();
  25.                
  26.                 if (action == "spend")
  27.                 {
  28.  
  29.                     sum = double.Parse(Console.ReadLine());
  30.  
  31.                     counter++;
  32.                     spendCounter++;
  33.  
  34.                     if (spendCounter == 5)
  35.                     {
  36.                         Console.WriteLine("You can't save the money." + "\r\n" + "{0}", spendCounter);
  37.                         break;
  38.  
  39.                     }
  40.  
  41.                     if (moneyAvailable < sum || moneyAvailable < 0)
  42.                     {
  43.                         moneyAvailable = 0;
  44.                     }
  45.                     else
  46.                     {
  47.                         moneyAvailable -= sum;
  48.                     }
  49.  
  50.                 }
  51.                 else if (action == "save")
  52.                 {
  53.                     counter++;
  54.                     spendCounter = 0;
  55.                     sum = double.Parse(Console.ReadLine());
  56.                     moneyAvailable += sum;
  57.                 }
  58.  
  59.                 if (moneyAvailable >= moneyForVacation)
  60.                 {
  61.                     Console.WriteLine("You saved the money for {0} days.", counter);
  62.                     break;
  63.                 }
  64.  
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement