nikolayneykov

Untitled

Oct 7th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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 Почивка___4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double neededmoney = double.Parse(Console.ReadLine());
  14.             double currentmone = double.Parse(Console.ReadLine());
  15.             double days = 0;
  16.             int spendingDays = 0;
  17.  
  18.             do
  19.             {
  20.                 string move = Console.ReadLine();
  21.                 double savespend = double.Parse(Console.ReadLine());
  22.                 days++;
  23.                 if (move == "save")
  24.                 {
  25.                     spendingDays = 0;
  26.                     currentmone += savespend;
  27.                 }
  28.                 if (move == "spend")
  29.                 {
  30.                     spendingDays++;
  31.                     currentmone -= savespend;
  32.                     if (currentmone <= 0)
  33.                     {
  34.                         currentmone = 0;
  35.                     }
  36.                 }
  37.  
  38.                 if (spendingDays > 4)
  39.                 {
  40.                     Console.WriteLine($"You can't save the money.");
  41.                     Console.WriteLine($"{days}");
  42.                     break;
  43.                 }
  44.             } while (currentmone < neededmoney);
  45.  
  46.             if (currentmone >= neededmoney)
  47.             {
  48.                 Console.WriteLine($"You saved the money for {days} days.");
  49.             }
  50.  
  51.  
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment