Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isOpen = true;
- int[] tables = { 4, 6, 8, 9, 7, 1, 3, 5 };
- int userTable;
- int userPlace;
- while (isOpen)
- {
- Console.WriteLine("Программа брони столов.\n");
- for (int i = 0; i < tables.Length; i++)
- {
- Console.WriteLine("Стол - " + (i + 1) + ". Свободно мест - " + tables[i]);
- }
- Console.WriteLine("\nДоступные команды:\n1 - Забронировать стол \n2 - Выход \n3 - Узнать, наибольшее кол-во свободных мест среди столов \n4 - Узнать, сколько всего свободных мест за столами");
- Console.Write("\nВведите номер команды:");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Console.Write("Введите номер стола:");
- userTable = Convert.ToInt32(Console.ReadLine()) - 1;
- if (userTable < 0 || userTable >= tables.Length)
- {
- Console.WriteLine("Такого стола нет.");
- break;
- }
- Console.Write("Введите кол-во мест:");
- userPlace = Convert.ToInt32(Console.ReadLine());
- if (userPlace > tables[userTable])
- {
- Console.WriteLine("Недостаточно мест.");
- break;
- }
- else if (userPlace < 0)
- {
- Console.WriteLine("Ну, вы не можете прибавить мест.");
- }
- else if (userPlace == 0)
- {
- Console.WriteLine("Ну, ноль мест вам не надо.");
- break;
- }
- tables[userTable] -= userPlace;
- break;
- case 2:
- isOpen = false;
- break;
- case 3:
- int max = 0;
- for (int i = 0; i < tables.Length; i++)
- {
- if (tables[i] > max)
- max = tables[i];
- }
- Console.WriteLine("наибольшее число мест " + max);
- break;
- case 4:
- int sum = 0;
- for (int i = 0; i < tables.Length; i++)
- {
- sum += tables[i];
- }
- Console.WriteLine("Всего свободных мест " + sum);
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement