Guest User

Vacation

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