Advertisement
knikolov98

Untitled

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