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 Les3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] table = { 4, 4, 7, 4, 6, 5 };
- int[] defaultTable = table;
- int mesta;
- while (true)
- {
- Console.Clear();
- for (int i = 0; i < table.Length; i++)
- {
- Console.WriteLine((i + 1) + " стол - свободных мест " + table[i]);
- }
- Console.WriteLine("Введите 0 чтобы выйти. Если гости уходят - введите количество уходящих гостей со знаком \"-\"");
- Console.Write("Введите номер стола:");
- int userInputTable = Convert.ToInt32(Console.ReadLine()) - 1;
- if (userInputTable == -1)
- break;
- if (userInputTable > table.Length - 1 || userInputTable<=1)
- {
- Console.Write("Такого стола нет.");
- Console.ReadKey();
- continue;
- }
- Console.Write("Введите кол-во мест:");
- int userInputPlace = Convert.ToInt32(Console.ReadLine());
- if (table[userInputTable] >= userInputPlace)
- {
- if (userInputPlace<0)
- {
- if (table[userInputTable] - userInputPlace > defaultTable[userInputTable]) //устранена возможность освобождения количества мест, больше изначального
- {
- Console.WriteLine("За этим столом не могло быть занято " + userInputPlace*-1 + " мест.");
- Console.ReadKey();
- continue;
- }
- }
- table[userInputTable] -= userInputPlace;
- }
- else
- {
- Console.WriteLine("За этим столом недостаточно мест.");
- for (mesta = 0; mesta < table.Length; mesta++) //добавлена функция указания номера подходящего стола для указанного количества гостей
- {
- if (table[mesta] >= userInputPlace)
- {
- Console.WriteLine("За столом " + (mesta+1) + " достаточно мест.");
- }
- }
- Console.ReadKey();
- continue;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement