Advertisement
Guest User

Untitled

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