Advertisement
Torgach

tempQueueAtTheStore

Mar 10th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace QueueAtTheStore
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int bank = 0;
  14.  
  15.             SetPrice(out Queue<int> purchase);
  16.  
  17.             for (int i = 0; purchase.Count > 0; ++i)
  18.             {
  19.                 bank += purchase.Peek();
  20.                 Console.WriteLine($"Клиент купил товар №{i + 1} на сумму: ${purchase.Dequeue()}");
  21.                 Console.WriteLine($"Наш счёт: ${bank}");
  22.                 Console.ReadKey();
  23.                 Console.Clear();
  24.             }
  25.  
  26.             Console.WriteLine($"Счет после обслуживания клиентов: ${bank}");
  27.         }
  28.  
  29.         static void SetPrice(out Queue<int> purchase)
  30.         {
  31.             bool isNumberParsed = false;
  32.  
  33.             int quantityOfItems = 0;
  34.             purchase = new Queue<int>();
  35.  
  36.             Random rand = new Random();
  37.  
  38.             while(isNumberParsed == false)
  39.             {
  40.                 Console.Write("Сколько товаров в магазине?\nВвод: ");
  41.  
  42.                 string userInput = Console.ReadLine();
  43.                 isNumberParsed = int.TryParse(userInput, out quantityOfItems );
  44.  
  45.                 if (isNumberParsed == false)
  46.                 {
  47.                     Console.WriteLine("Конвертация не удалась! Введите количество товаров.");
  48.                 }
  49.             }
  50.  
  51.             for (int i = 0; i < quantityOfItems; ++i)
  52.             {
  53.                 int priceOfItem = rand.Next(1, 100);
  54.                 purchase.Enqueue(priceOfItem);
  55.             }
  56.  
  57.             int count  = 1;
  58.             foreach (var item in purchase)
  59.             {
  60.                 Console.WriteLine($"[товар №{count}]: ${item}");
  61.                 count++;
  62.             }
  63.  
  64.             Console.WriteLine();
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement