Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace QueueAtTheStore
- {
- class Program
- {
- static void Main(string[] args)
- {
- int bank = 0;
- SetPrice(out Queue<int> purchase);
- for (int i = 0; purchase.Count > 0; ++i)
- {
- bank += purchase.Peek();
- Console.WriteLine($"Клиент купил товар №{i + 1} на сумму: ${purchase.Dequeue()}");
- Console.WriteLine($"Наш счёт: ${bank}");
- Console.ReadKey();
- Console.Clear();
- }
- Console.WriteLine($"Счет после обслуживания клиентов: ${bank}");
- }
- static void SetPrice(out Queue<int> purchase)
- {
- bool isNumberParsed = false;
- int quantityOfItems = 0;
- purchase = new Queue<int>();
- Random rand = new Random();
- while(isNumberParsed == false)
- {
- Console.Write("Сколько товаров в магазине?\nВвод: ");
- string userInput = Console.ReadLine();
- isNumberParsed = int.TryParse(userInput, out quantityOfItems );
- if (isNumberParsed == false)
- {
- Console.WriteLine("Конвертация не удалась! Введите количество товаров.");
- }
- }
- for (int i = 0; i < quantityOfItems; ++i)
- {
- int priceOfItem = rand.Next(1, 100);
- purchase.Enqueue(priceOfItem);
- }
- int count = 1;
- foreach (var item in purchase)
- {
- Console.WriteLine($"[товар №{count}]: ${item}");
- count++;
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement