Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Очередь_в_магазине
- {
- class Program
- {
- static void Main(string[] args)
- {
- int shopEarnings = 0;
- bool cycleWork = true;
- Queue<string> queueOfBuyers = new Queue<string>();
- queueOfBuyers.Enqueue("Покупатель №1");
- queueOfBuyers.Enqueue("Покупатель №2");
- queueOfBuyers.Enqueue("Покупатель №3");
- queueOfBuyers.Enqueue("Покупатель №4");
- while (cycleWork)
- {
- if (queueOfBuyers.Count != 0)
- {
- CustomerService(queueOfBuyers);
- SelectionProductWithPrice(ref shopEarnings);
- Console.SetCursorPosition(0, 10);
- Console.WriteLine($"Общая выручка магазина составляет: {shopEarnings} монеток");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- Console.WriteLine("Все клиенты обслужены.");
- cycleWork = false;
- }
- }
- }
- static void CustomerService(Queue<string> queueOfBuyers)
- {
- Console.WriteLine(queueOfBuyers.Dequeue());
- }
- static int SelectionProductWithPrice(ref int shopEarnings)
- {
- Random rand = new Random();
- int totalPurchaseAmount = 0;
- int quantityOfPurchasedGoods;
- int productPriceSelection = 0;
- List<int> productPrice = new List<int>();
- productPrice.AddRange(new int[] { 10, 20, 30, 50, 100, 150, 200 });
- quantityOfPurchasedGoods = rand.Next(1, productPrice.Count);
- for (int i = 0; i < quantityOfPurchasedGoods; i++)
- {
- productPriceSelection = rand.Next(0, productPrice.Count);
- for (int j = 0; j < productPrice.Count; j++)
- {
- if (j == productPriceSelection)
- {
- totalPurchaseAmount += productPrice[j];
- Console.WriteLine($"Покупатель приобрёл товар №{j} за {productPrice[j]} монеток");
- }
- }
- }
- shopEarnings += totalPurchaseAmount;
- Console.WriteLine($"\nОбщая сумма покупки составляет {totalPurchaseAmount} монеток");
- return shopEarnings;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement