Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 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 _03.Vacation
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double moneyVacation = double.Parse(Console.ReadLine());
  14.             double moneyAvailable = double.Parse(Console.ReadLine());
  15.  
  16.             string typeAction = string.Empty;
  17.             double sum = 0;
  18.             int countDays = 0;
  19.             int countSpendMoney = 0;
  20.  
  21.             while ((moneyAvailable < moneyVacation) && (countSpendMoney < 5))
  22.             {
  23.  
  24.                 countDays++;
  25.                 typeAction = Console.ReadLine();//spend or save
  26.                 sum = int.Parse(Console.ReadLine());
  27.  
  28.                 if (typeAction == "spend")
  29.                 {
  30.                     moneyAvailable -= sum;
  31.                     if (moneyAvailable < 0)
  32.                     {
  33.                         moneyAvailable = 0;
  34.                     }
  35.                     countSpendMoney++;
  36.                 }
  37.                 if (countSpendMoney == 5)
  38.                 {
  39.                     Console.WriteLine("You can't save the money.");
  40.                     Console.WriteLine(countDays);
  41.                     return;
  42.                 }
  43.                 else if (typeAction == "save")
  44.                 {
  45.                     countSpendMoney = 0;
  46.                     moneyAvailable += sum;
  47.                 }
  48.             }
  49.             if (moneyAvailable >= moneyVacation)
  50.             {
  51.                 Console.WriteLine($"You saved the money for {countDays} days.");
  52.  
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement