Advertisement
junniorrkaa

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

Apr 9th, 2025 (edited)
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 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 minValue = 10;
  13.             int maxValue = 50;
  14.             int purchaseAmount;
  15.  
  16.             Random random = new Random();
  17.  
  18.             int totalAmount = 0;
  19.             int clientsInQueue = 5;
  20.  
  21.             for (int i = 0; i < clientsInQueue; i++)
  22.             {
  23.                 clients.Enqueue(i + 1);
  24.             }
  25.  
  26.             while (clients.Count != 0)
  27.             {
  28.                 purchaseAmount = random.Next(minValue, maxValue);
  29.  
  30.                 Console.WriteLine($"Сейчас в очереди {clients.Dequeue()} клиент");
  31.                 Console.Write("\nСумма покупки: " + purchaseAmount);
  32.                 Console.Write("\nОбщая сумма: " + totalAmount);
  33.  
  34.                 totalAmount += purchaseAmount;
  35.  
  36.                 Console.ReadKey();
  37.                 Console.Clear();
  38.             }
  39.  
  40.             Console.Write("Клиентов больше нет. Итоговая общая сумма: " + totalAmount + "\n");
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement