nikolayneykov

Untitled

Oct 11th, 2018
156
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 vacation
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double vacationCost = double.Parse(Console.ReadLine());
  14.             double money = double.Parse(Console.ReadLine());
  15.             int counter = 0;
  16.             int days = 0;
  17.             do
  18.             {
  19.                 string command = Console.ReadLine();
  20.                 double transfer = double.Parse(Console.ReadLine());
  21.                 days++;
  22.                 if (command == "spend")
  23.                 {
  24.                     money -= transfer;
  25.                     counter++;
  26.                     if (transfer >= money)
  27.                     {
  28.                         money = 0;
  29.                     }
  30.                     if (counter == 5)
  31.                     {
  32.                         Console.WriteLine("You can't save the money.");
  33.                         Console.WriteLine(days);
  34.                         break;
  35.                     }
  36.                 }
  37.                 else if (command == "save")
  38.                 {
  39.                     money += transfer;
  40.                     counter = 0;
  41.                 }
  42.                 if (vacationCost <= money)
  43.                 {
  44.                     Console.WriteLine($"You saved the money for {days} days.");
  45.                     break;
  46.                 }
  47.             } while (money < vacationCost);
  48.  
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment