Advertisement
junniorrkaa

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

Apr 9th, 2025 (edited)
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CSLight
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             Queue<int> clients = new Queue<int>();
  11.  
  12.             int totalAmount = 0;
  13.  
  14.             DeclareQueue(clients);
  15.  
  16.             while (clients.Count != 0)
  17.             {
  18.                 ServeQueue(clients, ref totalAmount);
  19.  
  20.                 Console.ReadKey();
  21.                 Console.Clear();
  22.             }
  23.  
  24.             Console.Write("Очередь пуста. Итоговая общая сумма: " + totalAmount + "\n");
  25.         }
  26.  
  27.         static Queue<int> DeclareQueue(Queue<int> clients)
  28.         {
  29.             int clientsInQueue = 5;
  30.             int minValue = 10;
  31.             int maxValue = 50;
  32.  
  33.             Random random = new Random();
  34.  
  35.             for (int i = 0; i < clientsInQueue; i++)
  36.             {
  37.                 clients.Enqueue(random.Next(minValue, maxValue));
  38.             }
  39.  
  40.             return clients;
  41.         }
  42.  
  43.         static void ServeQueue(Queue<int> clients, ref int totalAmount)
  44.         {
  45.             Console.Write("Сумма покупки: " + clients.Peek());
  46.             Console.Write("\n\nОбщая сумма: " + totalAmount);
  47.  
  48.             totalAmount += clients.Dequeue();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement