Advertisement
RamGaal

Homework 3 ex.1

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