CrewLab

day 03_1

May 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 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.             // теперь пользователь не видит столы за которыми не осталось мест
  14.             // и есть защита от ввода отрицательных чисел.
  15.             int[] table = { 4, 4, 7, 4, 6, 5 };
  16.  
  17.             while (true)
  18.             {
  19.                 Console.Clear();
  20.  
  21.                 for (int i = 0; i < table.Length; i++)
  22.                 {
  23.                     if (table[i] != 0)
  24.                         Console.WriteLine((i + 1) + " стол - свободных мест " + table[i]);
  25.                 }
  26.                 Console.WriteLine("Введите 0 чтобы выйти.");
  27.  
  28.                 Console.Write("Введите номер стола:");
  29.                 int userInputTable = Convert.ToInt32(Console.ReadLine()) - 1;
  30.  
  31.                 if (userInputTable == -1)
  32.                     break;
  33.  
  34.                 if (userInputTable > table.Length - 1)
  35.                 {
  36.                     Console.Write("Такого стола нет.");
  37.                     Console.ReadKey();
  38.                     continue;
  39.                 }
  40.  
  41.  
  42.                 Console.Write("Введите кол-во мест:");
  43.                 int userInputPlace = Convert.ToInt32(Console.ReadLine());
  44.  
  45.                 if (table[userInputTable] >= userInputPlace && userInputPlace > 0)
  46.                     table[userInputTable] -= userInputPlace;
  47.                 else if (table[userInputTable] >= userInputPlace && userInputPlace > 0)
  48.                 {
  49.                     Console.WriteLine("За этим столом недостаточно мест.");
  50.                     Console.ReadKey();
  51.                     continue;
  52.                 }
  53.                 else
  54.                 {
  55.                     Console.WriteLine("Вы не можете вводить отрицательные числа.");
  56.                     Console.ReadKey();
  57.                     continue;
  58.                 }
  59.             }
  60.  
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment