Advertisement
aggressiveviking

Untitled

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