Advertisement
SPavelA

Task2Queue

Sep 23rd, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CollectionsTask2Queue
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Queue<int> clientsMoney = new Queue<int>();
  14.             int clientMoney;
  15.             int ourMoney = 0;
  16.  
  17.             Random random = new Random();
  18.  
  19.             for (int i = 0; i < 10; i++)
  20.             {
  21.                 clientsMoney.Enqueue(random.Next(0, 10000));
  22.             }
  23.  
  24.             while(clientsMoney.Count > 0)
  25.             {
  26.                 Console.Clear();
  27.                 clientMoney = clientsMoney.Dequeue();
  28.                 Console.WriteLine($"Следующий клиент совершает покупку на {clientMoney} монет.");
  29.                 ourMoney += clientMoney;
  30.                 Console.WriteLine($"В кассе магазина теперь {ourMoney} монет.");
  31.                 Console.ReadKey();
  32.             }
  33.  
  34.             Console.WriteLine($"Покупателей больше нет.");
  35.             Console.ReadKey();
  36.         }
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement