Advertisement
SaNik74

ShopQueue

Jun 20th, 2024 (edited)
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. namespace ShopQueue
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             int shopBalance = 0;
  8.  
  9.             Queue<int> purchase = new Queue<int>();
  10.  
  11.             FillQueue(purchase);
  12.             shopBalance = SellProduct(purchase, shopBalance);
  13.             ShowShopBalance(shopBalance);
  14.         }
  15.  
  16.         static void ShowShopBalance(int shopBalance)
  17.         {
  18.             Console.WriteLine($"Средств на балансе магазина - {shopBalance}");
  19.         }
  20.  
  21.         static void FillQueue(Queue<int> queue)
  22.         {
  23.             Random random = new Random();
  24.            
  25.             int maxNumbersPurchase = 20;
  26.             int minNumbersPurchase = 1;
  27.             int maxCostPurchase = 2000;
  28.             int minCostPurchase = 1;
  29.  
  30.             int purchaseNumbers = random.Next(minNumbersPurchase, maxNumbersPurchase + 1);
  31.            
  32.             for (int i = 0; i < purchaseNumbers; i++)
  33.             {
  34.                 queue.Enqueue(random.Next(minCostPurchase, maxCostPurchase));
  35.             }
  36.         }
  37.  
  38.         static int SellProduct(Queue<int> queue, int shopBalance)
  39.         {
  40.            while(queue.Count > 0)
  41.             {
  42.                 ShowQueueInfo(queue);
  43.                 Console.WriteLine($"На балансе {shopBalance}.");
  44.                 shopBalance += queue.Dequeue();
  45.                 Console.ReadKey();
  46.                 Console.Clear();
  47.             }
  48.  
  49.            return shopBalance;
  50.         }
  51.  
  52.         static void ShowQueueInfo(Queue<int> queue)
  53.         {
  54.             Console.WriteLine("Стоимость каждой покупки в очереди");
  55.            
  56.             foreach (int pricePurchse in queue)
  57.             {
  58.                 Console.Write(pricePurchse + "||");
  59.             }
  60.  
  61.             Console.WriteLine();
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement