CrewLab

day 03_1

May 19th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Les3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] table = { 4, 4, 7, 4, 6, 5 };
  14.  
  15.             // теперь пользователь не видит столы за которыми не осталось мест
  16.             while (true)
  17.             {
  18.                 Console.Clear();
  19.  
  20.                 for (int i = 0; i < table.Length; i++)
  21.                 {
  22.                     if (table[i] != 0)
  23.                         Console.WriteLine((i + 1) + " стол - свободных мест " + table[i]);
  24.                 }
  25.                 Console.WriteLine("Введите 0 чтобы выйти.");
  26.  
  27.                 Console.Write("Введите номер стола:");
  28.                 int userInputTable = Convert.ToInt32(Console.ReadLine()) - 1;
  29.  
  30.                 if (userInputTable == -1)
  31.                     break;
  32.  
  33.                 if (userInputTable > table.Length - 1)
  34.                 {
  35.                     Console.Write("Такого стола нет.");
  36.                     Console.ReadKey();
  37.                     continue;
  38.                 }
  39.  
  40.  
  41.                 Console.Write("Введите кол-во мест:");
  42.                 int userInputPlace = Convert.ToInt32(Console.ReadLine());
  43.  
  44.                 if (table[userInputTable] >= userInputPlace)
  45.                     table[userInputTable] -= userInputPlace;
  46.                 else
  47.                 {
  48.                     Console.WriteLine("За этим столом недостаточно мест.");
  49.                     Console.ReadKey();
  50.                     continue;
  51.                 }
  52.             }
  53.  
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment