RedFlys

СSharpLigth HomeWork - Queue

Jan 28th, 2021 (edited)
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace СSharpLigth_HomeWork___Queue
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int cash = 134;
  11.  
  12.             Queue<int> buyers = new Queue<int>();
  13.  
  14.             buyers.Enqueue(512);
  15.             buyers.Enqueue(1024);
  16.             buyers.Enqueue(718);
  17.             buyers.Enqueue(541);
  18.             buyers.Enqueue(51);
  19.  
  20.             while (buyers.Count > 0)
  21.             {
  22.                 ShowCash(cash);
  23.                 ShowCountQueue(buyers.Count);
  24.                 var bayer = buyers.Dequeue();
  25.  
  26.                 Console.WriteLine($"Сумма покупки - {bayer} руб.");
  27.                 cash += bayer;
  28.                 Console.ReadKey();
  29.                 Console.Clear();
  30.             }
  31.  
  32.             Console.WriteLine("В очереди больше нет людей.");
  33.             ShowCash(cash);
  34.             Console.ReadKey();
  35.         }
  36.  
  37.         public static void ShowCash(int cash)
  38.         {
  39.             Console.WriteLine($"В кассе {cash} рублей.");
  40.         }
  41.  
  42.         public static void ShowCountQueue(int count)
  43.         {
  44.             if (count > 1 && count < 5)
  45.             {
  46.                 Console.WriteLine($"В очереди сейчас {count} человека.");
  47.             }
  48.             else
  49.             {
  50.                 Console.WriteLine($"В очереди сейчас {count} человек.");
  51.             }
  52.         }
  53.     }
  54. }
Add Comment
Please, Sign In to add comment