Advertisement
veselka_a

04.EasterShop

Feb 25th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 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 _4.EasterShop
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int easterEggs = int.Parse(Console.ReadLine());
  14.            
  15.             string input = Console.ReadLine();
  16.             int solddEggs = 0;
  17.             int filledEggs = 0;
  18.             int totalSoldEggs = 0;
  19.  
  20.             while (input!="Close")
  21.             {
  22.                 if (input=="Buy")
  23.                 {
  24.                     solddEggs = int.Parse(Console.ReadLine());
  25.                     if (solddEggs > easterEggs)
  26.                     {
  27.                         Console.WriteLine($"Not enough eggs in store!");
  28.                         Console.WriteLine($"You can buy only {easterEggs}.");
  29.                         return;
  30.                     }
  31.                     else if (solddEggs <= easterEggs)
  32.                     {
  33.                         easterEggs -= solddEggs;
  34.                         totalSoldEggs += solddEggs;
  35.                     }
  36.                    
  37.                 }
  38.                 else if(input=="Fill")
  39.                 {
  40.                     filledEggs = int.Parse(Console.ReadLine());
  41.                     easterEggs += filledEggs;
  42.                    
  43.                 }
  44.                 input = Console.ReadLine();
  45.  
  46.             }
  47.             Console.WriteLine($"Store is closed!");
  48.             Console.WriteLine($"{totalSoldEggs} eggs sold.");
  49.  
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement