anizko

03. Vacation

Apr 4th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Vacation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             double Vacation = double.Parse(Console.ReadLine());
  11.             double AveableMoney = double.Parse(Console.ReadLine());
  12.  
  13.             int Spend = 0;
  14.             int CountDay = 0;
  15.            
  16.  
  17.             while(Spend<5 && Vacation> AveableMoney)
  18.             {
  19.                 string SpendSave = Console.ReadLine();
  20.                 double SpendSaveMoney = double.Parse(Console.ReadLine());
  21.  
  22.                 if (SpendSave =="save")
  23.                 {
  24.                     AveableMoney += SpendSaveMoney;
  25.                     Spend = 0;
  26.                 }
  27.                 else if(SpendSave == "spend")
  28.                 {
  29.                     if (AveableMoney - SpendSaveMoney < 0)
  30.                     {
  31.                         AveableMoney = 0;
  32.                     }
  33.                     else
  34.                     {
  35.                         AveableMoney -= SpendSaveMoney;
  36.                     }
  37.                     Spend++;
  38.                 }
  39.                 CountDay++;
  40.             }
  41.  
  42.             if(Spend == 5)
  43.             {
  44.                 Console.WriteLine("You can't save the money.");
  45.                 Console.WriteLine(CountDay);
  46.             }
  47.             else if(Vacation <= AveableMoney)
  48.             {
  49.                 Console.WriteLine($"You saved the money for {CountDay} days.");
  50.             }
  51.  
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment