Advertisement
ralichka

Exam.20-21.April-04.Easter.Shop

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