Advertisement
AziLif

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

Apr 11th, 2025 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Queue<int> buyers = new Queue<int>();
  10.  
  11.             int storeAccount = 0;
  12.  
  13.             AddChecks(buyers);
  14.  
  15.             bool isSale = true;
  16.  
  17.             Console.Clear();
  18.  
  19.             while (isSale)
  20.             {
  21.                 if (buyers.Count > 0)
  22.                 {
  23.                     ServeCustomer(buyers, storeAccount);
  24.                 }
  25.                 else
  26.                 {
  27.                     isSale = false;
  28.  
  29.                     Console.WriteLine("Спасибо что воспользовались нашим магазином! Досвидания.");
  30.  
  31.                     Console.ReadKey();
  32.                 }
  33.             }
  34.         }
  35.  
  36.         static void AddChecks(Queue<int> buyers)
  37.         {
  38.             string checkAmount;
  39.  
  40.             int lengthCollection = 4;
  41.  
  42.             Console.WriteLine($"Введите {lengthCollection} цифр готовых чеков.");
  43.  
  44.             while (int.TryParse(checkAmount = Console.ReadLine(), out int amountPurchase) == false || buyers.Count < lengthCollection)
  45.             {
  46.                 buyers.Enqueue((int)amountPurchase);
  47.             }
  48.         }
  49.  
  50.         static void ShowQueue(Queue<int> buyers)
  51.         {
  52.             Console.Clear();
  53.  
  54.             Console.CursorVisible = false;
  55.  
  56.             Console.SetCursorPosition(0, 2);
  57.  
  58.             foreach (var item in buyers)
  59.             {
  60.                 Console.WriteLine(item);
  61.             }
  62.         }
  63.  
  64.         static int ServeCustomer(Queue<int> buyers, int storeAccount)
  65.         {
  66.             const ConsoleKey CommandСontinueCounting = ConsoleKey.Enter;
  67.  
  68.             string commanContinue = "Ввод";
  69.  
  70.             while (buyers.Count > 0)
  71.             {
  72.                 Console.WriteLine($"Для продолжения обслуживания нажмите \'{commanContinue}\'");
  73.  
  74.                 ConsoleKeyInfo exit = Console.ReadKey();
  75.  
  76.                 ShowQueue(buyers);
  77.  
  78.                 if (exit.Key == CommandСontinueCounting)
  79.                 {
  80.                     storeAccount += buyers.Dequeue();
  81.                 }
  82.  
  83.                 UpdateAccountOfStore(storeAccount);
  84.             }
  85.  
  86.             return storeAccount;
  87.         }
  88.  
  89.         static void UpdateAccountOfStore(int totalAmountPurchases)
  90.         {
  91.             Console.SetCursorPosition(30, 3);
  92.  
  93.             Console.WriteLine($"Общий счет магазина {totalAmountPurchases}.");
  94.  
  95.             Console.SetCursorPosition(0, 0);
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement