Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StartCode]
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- /* У вас есть множество целых чисел. Каждое целое число - это сумма покупки.
- Вам нужно обслуживать клиентов до тех пор, пока очередь не станет пуста.
- После каждого обслуженного клиента деньги нужно добавлять на наш счёт и выводить его в консоль.
- После обслуживания каждого клиента программа ожидает нажатия любой клавиши, после чего затирает консоль и по новой выводит всю информацию, только уже со следующим клиентом
- */
- namespace ConsoleApp7
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int cashbox = 0;
- Queue<int> amounts = new Queue<int>();
- AddInQueue(amounts);
- for (int i = amounts.Count; i > 0; i--)
- {
- DisplayQueue(amounts);
- ServiseQueue(amounts, ref cashbox);
- Console.ReadKey();
- DisplayCashBox(cashbox);
- }
- }
- static void AddInQueue(Queue<int> amounts)
- {
- amounts.Enqueue(6);
- amounts.Enqueue(3);
- amounts.Enqueue(3);
- amounts.Enqueue(92);
- amounts.Enqueue(30);
- }
- static void DisplayCashBox(int cashbox)
- {
- Console.Clear();
- Console.WriteLine("В кассе :" + cashbox + " рублей.");
- }
- static void DisplayQueue(Queue<int> amounts)
- {
- Console.Write("Очередь покупок : ");
- foreach (int sum in amounts)
- {
- Console.Write(" " + sum);
- }
- }
- static void ServiseQueue(Queue<int> amounts, ref int cashbox)
- {
- cashbox += amounts.Dequeue();
- }
- }
- }
- [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment