Advertisement
voldmaks

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

Jul 21st, 2021
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 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 Очередь_в_магазине
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int shopEarnings = 0;
  14.             bool cycleWork = true;
  15.  
  16.             Queue<string> queueOfBuyers = new Queue<string>();
  17.  
  18.             queueOfBuyers.Enqueue("Покупатель №1");
  19.             queueOfBuyers.Enqueue("Покупатель №2");
  20.             queueOfBuyers.Enqueue("Покупатель №3");
  21.             queueOfBuyers.Enqueue("Покупатель №4");
  22.  
  23.             while (cycleWork)
  24.             {
  25.                 if (queueOfBuyers.Count != 0)
  26.                 {
  27.                     CustomerService(queueOfBuyers);
  28.                     SelectionProductWithPrice(ref shopEarnings);
  29.  
  30.                     Console.SetCursorPosition(0, 10);
  31.                     Console.WriteLine($"Общая выручка магазина составляет: {shopEarnings} монеток");
  32.  
  33.                     Console.ReadKey();
  34.                     Console.Clear();
  35.                 }
  36.                 else
  37.                 {
  38.                     Console.WriteLine("Все клиенты обслужены.");
  39.                     cycleWork = false;
  40.                 }
  41.             }
  42.         }
  43.  
  44.         static void CustomerService(Queue<string> queueOfBuyers)
  45.         {
  46.             Console.WriteLine(queueOfBuyers.Dequeue());
  47.         }
  48.  
  49.         static int SelectionProductWithPrice(ref int shopEarnings)
  50.         {
  51.             Random rand = new Random();
  52.             int totalPurchaseAmount = 0;
  53.             int quantityOfPurchasedGoods;
  54.             int productPriceSelection = 0;
  55.  
  56.             List<int> productPrice = new List<int>();
  57.             productPrice.AddRange(new int[] { 10, 20, 30, 50, 100, 150, 200 });
  58.  
  59.             quantityOfPurchasedGoods = rand.Next(1, productPrice.Count);
  60.  
  61.             for (int i = 0; i < quantityOfPurchasedGoods; i++)
  62.             {
  63.                 productPriceSelection = rand.Next(0, productPrice.Count);
  64.                 for (int j = 0; j < productPrice.Count; j++)
  65.                 {
  66.                     if (j == productPriceSelection)
  67.                     {
  68.                         totalPurchaseAmount += productPrice[j];
  69.                         Console.WriteLine($"Покупатель приобрёл товар №{j} за {productPrice[j]} монеток");
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             shopEarnings += totalPurchaseAmount;
  75.  
  76.             Console.WriteLine($"\nОбщая сумма покупки составляет {totalPurchaseAmount} монеток");
  77.  
  78.             return shopEarnings;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement