Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- static void Main(string[] args)
- {
- int accountBalance = 0;
- Queue<int> purchaseAmounts = new Queue<int>();
- FillQueue(purchaseAmounts);
- accountBalance = ServeClients(purchaseAmounts);
- Console.WriteLine($"На счете - {accountBalance}");
- }
- static void FillQueue(Queue<int> queue)
- {
- bool isNumber = false;
- int numbersOfValues = 0;
- while (isNumber == false)
- {
- Console.Write("Сколько значений собираетесь ввести?: ");
- isNumber = ChekNumber(out numbersOfValues);
- if (isNumber == false)
- {
- Console.WriteLine("Вы ввели не число.");
- Console.ReadKey();
- }
- Console.Clear();
- }
- for (int i = 0; i < numbersOfValues; i++)
- {
- Console.Write($"Введите значение: ");
- isNumber = ChekNumber(out int value);
- if (isNumber == true)
- {
- queue.Enqueue(value);
- }
- else
- {
- Console.WriteLine("Вы ввели не число.");
- i--;
- Console.ReadKey();
- }
- Console.Clear();
- }
- }
- static int ServeClients(Queue<int> queue)
- {
- int totalValues = 0;
- while(queue.Count > 0 )
- {
- totalValues += queue.Dequeue();
- Console.WriteLine($"Сумма = {totalValues}");
- Console.ReadKey();
- Console.Clear();
- }
- return totalValues;
- }
- static bool ChekNumber (out int number)
- {
- bool isNumber = int.TryParse(Console.ReadLine(), out number);
- return isNumber;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement