Advertisement
Guest User

C# 04. Vacation

a guest
Oct 12th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 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 needed = double.Parse(Console.ReadLine());
  14.             double money = double.Parse(Console.ReadLine());
  15.             int spendcount = 0;
  16.             int days = 0;
  17.  
  18.             while(true)
  19.             {
  20.                 string action = Console.ReadLine();
  21.                 double amount = double.Parse(Console.ReadLine());
  22.                 days++;
  23.                 switch(action)
  24.                 {
  25.                     case "spend": money -= amount; spendcount++;
  26.                         if (money < 0)
  27.                         {
  28.                             money = 0;
  29.                         } break;
  30.                     case "save": money += amount; break;
  31.                 }
  32.                 if(spendcount == 5)
  33.                 {
  34.                     Console.WriteLine("You can't save the money.");
  35.                     Console.WriteLine($"{days}");
  36.                     break;
  37.                 }
  38.                 else if(money >= needed)
  39.                 {
  40.                     Console.WriteLine($"You saved the money for {days} days.");
  41.                     break;
  42.                 }
  43.  
  44.  
  45.  
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement