Advertisement
NikaBang

Очередь в магазине

Oct 22nd, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. internal class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Queue<int> buyers = new Queue<int>();
  9.  
  10.         int sumPurchase = 0;
  11.         int minPurchase = 100;
  12.         int maxPurchase = 10000;
  13.         int minBuyers = 1;
  14.         int maxBuyers = 11;
  15.  
  16.         int countBuyers = ReturnRandomNumber(minBuyers, maxBuyers);
  17.  
  18.         for (int i = 0; i < countBuyers; i++)
  19.         {
  20.             buyers.Enqueue(ReturnRandomNumber(minPurchase, maxPurchase));
  21.         }
  22.  
  23.         for (int i = 0; i < buyers.Count; i++)
  24.         {
  25.             sumPurchase += buyers.Dequeue();
  26.         }
  27.  
  28.         Console.WriteLine($"Сегодня было {countBuyers} покупателей и они купили на {sumPurchase} рублей.");
  29.         Console.ReadKey();
  30.     }
  31.  
  32.     static int ReturnRandomNumber(int minNumber, int maxNumber)
  33.     {
  34.         Random random = new Random();
  35.  
  36.         int number = random.Next(minNumber, maxNumber);
  37.  
  38.         return number;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement