Advertisement
knoteva

Untitled

Oct 9th, 2019
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. namespace ConditionalProject
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             double moneyNeededForTrip = double.Parse(Console.ReadLine());
  9.             double currentMoney = double.Parse(Console.ReadLine());
  10.  
  11.             int days = 0;
  12.             int spentDays = 0; // каунт дните, в които харчи
  13.  
  14.             while (true)
  15.             {
  16.                 string toDo = Console.ReadLine();
  17.                 double moneyToSpend = double.Parse(Console.ReadLine());
  18.                 days++;
  19.                 if (toDo == "save")
  20.                 {
  21.                     currentMoney = moneyToSpend + currentMoney;
  22.                     spentDays = 0; // Ако спестява го нулираме(5 последователни)
  23.                 }
  24.                 else if (toDo == "spend") // Няма нужда от допълнителната проверка.
  25.                 {
  26.                     currentMoney = currentMoney - moneyToSpend;
  27.                     spentDays++; // Ако харчи го увеличаваме
  28.                 }
  29.                 if (currentMoney < 0)
  30.                 {
  31.                     currentMoney = 0;
  32.                 }
  33.                 if (spentDays == 5)
  34.                 {
  35.                     Console.WriteLine("You can't save the money.");
  36.                     Console.WriteLine($"{days}");
  37.                     break;
  38.                 }
  39.                 else if (currentMoney >= moneyNeededForTrip)
  40.                 {
  41.                     Console.WriteLine($"You saved the money for {days} days.");
  42.                     break;
  43.                 }
  44.  
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement