desito07

05. Vacation

Sep 23rd, 2023 (edited)
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. namespace _1
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             double moneyNeeded = double.Parse(Console.ReadLine());
  8.             double moneyAvailable = double.Parse(Console.ReadLine());
  9.             string command = Console.ReadLine();
  10.             int counter = 0;
  11.             int counterSpending = 0;
  12.  
  13.  
  14.             while (counterSpending < 5)
  15.             {
  16.  
  17.                 if (moneyAvailable >= moneyNeeded)
  18.                 {
  19.                     break;
  20.                 }
  21.                 counter++;
  22.                 int currentMoney = int.Parse(Console.ReadLine());
  23.  
  24.                 if (command == "spend")
  25.                 {
  26.                     moneyAvailable -= currentMoney;
  27.                     counterSpending++;
  28.                 }
  29.                 if (command == "save")
  30.                 {
  31.                     moneyAvailable += currentMoney;
  32.                     counterSpending = 0;
  33.                 }
  34.                 if (moneyAvailable < 0)
  35.                 {
  36.                     moneyAvailable = 0;
  37.                 }
  38.  
  39.                 command = Console.ReadLine();
  40.             }
  41.             if (moneyAvailable >= moneyNeeded)
  42.             {
  43.                 Console.WriteLine($"You saved the money for {counter} days.");
  44.             }
  45.             else
  46.             {
  47.                 Console.WriteLine("You can't save the money.");
  48.                 Console.WriteLine($"{counter}");
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment