Advertisement
silvana1303

easter shop

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