Advertisement
nikolayneykov

Untitled

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