Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. namespace P4_Random_test
  2. {
  3. using System;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. int eggInStoreCount = int.Parse(Console.ReadLine());
  10. string input = Console.ReadLine();
  11.  
  12. int soldEggs = 0;
  13.  
  14. while (input != "Close")
  15. {
  16. int eggs = int.Parse(Console.ReadLine());
  17.  
  18. if (input == "Buy")
  19. {
  20. if (eggInStoreCount - eggs < 0)
  21. {
  22. Console.WriteLine($"Not enough eggs in store!");
  23. Console.WriteLine($"You can buy only {eggInStoreCount}.");
  24.  
  25. return;
  26. }
  27.  
  28. eggInStoreCount -= eggs;
  29. soldEggs += eggs;
  30. }
  31. else
  32. {
  33. eggInStoreCount += eggs;
  34. }
  35.  
  36. input = Console.ReadLine();
  37. }
  38.  
  39. Console.WriteLine($"Store is closed!");
  40. Console.WriteLine($"{soldEggs} eggs sold.");
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement