Advertisement
MaoChessy

Task 25

Oct 30th, 2020 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace C_sharp_Light
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Queue<int> buyers = new Queue<int>();
  10.             bool isOpen = true;
  11.             int money = 0;
  12.  
  13.             buyers = FillQueue();
  14.             Console.WriteLine("Очередь заполнена");
  15.  
  16.             while (buyers.Count>0 && isOpen)
  17.             {
  18.                  
  19.                 Console.WriteLine($"Нажмите Esc для выхода \n\n\n");
  20.                 Console.WriteLine($"Денег: {money}\nВ очереди - {buyers.Count}");
  21.                 Console.WriteLine($"У следующего покупателя сумма покупок = {buyers.Peek()}; \n\nНажмите - Enter - для обработки \nПробел - для пропуска покупателя до следующий итерации");
  22.  
  23.                 ConsoleKeyInfo key = Console.ReadKey();
  24.                 switch (key.Key)
  25.                 {
  26.                     case ConsoleKey.Enter:
  27.                         Console.WriteLine("Покупатель обработан");
  28.                         money+=buyers.Dequeue();
  29.                         Console.ReadKey();
  30.                         break;
  31.                     case ConsoleKey.Spacebar:
  32.                         Console.WriteLine("Вы оставили покупателя на след. итерацию");
  33.                         Console.ReadKey();
  34.                         break;
  35.                     case ConsoleKey.Escape:
  36.                         isOpen = false;
  37.                         break;
  38.                 }
  39.                 Console.Clear();
  40.             }
  41.             if (isOpen!=false)
  42.             {
  43.                 Console.Clear();
  44.                 Console.WriteLine($"Все покупатели обслужены. Вы заработали {money}");
  45.                 Console.ReadKey();
  46.             }
  47.             else
  48.             {
  49.                 Console.Clear();
  50.                 Console.WriteLine($"Все прервали свой рабочий день, не обслужили всех покупателей. Вы заработали {money}");
  51.                 Console.ReadKey();
  52.             }
  53.         }
  54.  
  55.         static Queue<int> FillQueue()
  56.         {
  57.             Random rand = new Random();
  58.             Queue<int> result = new Queue<int>();
  59.             for (int i = 0; i < rand.Next(3,13); i++)
  60.             {
  61.                 result.Enqueue(rand.Next(50, 1000));
  62.             }
  63.             return result;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement