Advertisement
Montagne94

25. Очередь в магазине

Oct 14th, 2020 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int cashBox = 0;
  11.  
  12.             Random random = new Random();
  13.             Queue<int> checkBuyers = new Queue<int>();
  14.             checkBuyers.Enqueue(random.Next(1000));
  15.             checkBuyers.Enqueue(random.Next(1000));
  16.             checkBuyers.Enqueue(random.Next(1000));
  17.             checkBuyers.Enqueue(random.Next(1000));
  18.             checkBuyers.Enqueue(random.Next(1000));
  19.             checkBuyers.Enqueue(random.Next(1000));
  20.             checkBuyers.Enqueue(random.Next(1000));
  21.             checkBuyers.Enqueue(random.Next(1000));
  22.             checkBuyers.Enqueue(random.Next(1000));
  23.  
  24.             BuyProduct(checkBuyers, ref cashBox);
  25.  
  26.             Console.WriteLine($"Итого магазин заработал {cashBox}$");
  27.             Console.ReadKey();
  28.         }
  29.  
  30.         static void BuyProduct(Queue<int> checkBuyers, ref int cashBox)
  31.         {
  32.             int clientNumber = 1;
  33.             while (checkBuyers.Count > 0)
  34.             {
  35.                 Console.WriteLine($"Сумма покупки {clientNumber} покупателя = {checkBuyers.Peek()}$");
  36.                 Console.WriteLine($"Игото в кассе {cashBox += checkBuyers.Dequeue()}$");
  37.                 clientNumber++;
  38.  
  39.                 Console.ReadKey();
  40.                 Console.Clear();
  41.             }
  42.         }
  43.  
  44.  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement