Dr_Max_Experience

Tack 26

Dec 6th, 2021 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace HomeWorks
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Queue<int> prices = new Queue<int>();
  12.             int sum = 0;
  13.             bool isOpen = true;
  14.  
  15.             while (isOpen)
  16.             {
  17.                 Console.Clear();
  18.                 ServeBuyer(prices, ref isOpen);
  19.                 Console.ReadKey();
  20.             }
  21.  
  22.             foreach(var price in prices)
  23.             {
  24.                 sum += price;
  25.             }
  26.  
  27.             Console.Write($"За сегодня, выручка составила: {sum}.\nДля выхода из програмы, нажмите любую клавишу...");
  28.             Console.ReadKey();
  29.         }
  30.  
  31.         static void ServeBuyer(Queue<int> prices, ref bool isOpen)
  32.         {
  33.             int buyerNumber = 0;
  34.  
  35.             while (isOpen)
  36.             {
  37.                 Console.Clear();
  38.                 Console.Write($"ОБСЛУЖИВАНИЕ КЛИЕНТА №{++buyerNumber}\n\nвведите end, когда обслужите покупателя\n\nВведите сумму покупки: ");
  39.                 string userInput = Console.ReadLine();
  40.  
  41.                 if (int.TryParse(userInput, out int price))
  42.                 {
  43.                     prices.Enqueue(price);
  44.                 }
  45.                 else if (userInput == "end")
  46.                 {
  47.                     isOpen = false;
  48.                 }
  49.                 else
  50.                 {
  51.                     Console.WriteLine("Такой команды нет!");
  52.                     Console.ReadKey();
  53.                 }
  54.             }
  55.  
  56.             Console.Clear();
  57.         }
  58.     }
  59. }
Add Comment
Please, Sign In to add comment