Advertisement
Guest User

Untitled

a guest
Apr 24th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int eggs =int.Parse(Console.ReadLine());
  10.             int soldEggs = 0;
  11.            
  12.             while (true)
  13.             {
  14.                 string command =Console.ReadLine();
  15.                
  16.                 if (command == "Close")
  17.                 {
  18.                     Console.WriteLine("Store is closed!");
  19.                     Console.WriteLine($"{soldEggs } eggs sold.");
  20.                     break;
  21.                 }
  22.                 int eggsCount = int.Parse(Console.ReadLine());
  23.                 if (command == "Fill")
  24.                 {
  25.                     eggs += eggsCount;
  26.                    
  27.                 }
  28.                 if (command == "Buy")
  29.                 {
  30.                     if (eggs > eggsCount)
  31.                     {
  32.                         eggs -= eggsCount;
  33.                         soldEggs += eggsCount;
  34.                        
  35.                     }
  36.                     else
  37.                     {
  38.                         Console.WriteLine("Not enough eggs in store!");
  39.                         Console.WriteLine($"You can buy only {eggs}.");
  40.                     }
  41.                 }
  42.  
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement