Closet Service CLI
unknown
csharp
2 years ago
1.3 kB
6
Indexable
string[] closet1 = new string[] { "ПУСТО", "ТЕЛЕВИЗОР", "ПУСТО", "ПУСТО", "ШКАТУЛКА", }; void ShowShelves(string[] closet) { for (int i = 0; i < closet.Length; i++) { Console.WriteLine($"ПОЛКА [{i + 1}]: {closet[i]}"); } } while (true) { ShowShelves(closet1); bool isEmpty = false; foreach (var item in closet1) { if (item == "ПУСТО") { isEmpty = true; break; } } if (!isEmpty) { Console.WriteLine("Нет свободных мест"); break; } Console.WriteLine("Какой предмет хотите добавить?"); string inputItem = Console.ReadLine(); Console.WriteLine("На какую полку?"); int inputShelfIndex = Convert.ToInt32(Console.ReadLine()) - 1; if (inputShelfIndex <= 0 && inputShelfIndex >= closet1.Length) { Console.WriteLine("Ошибка"); } else { if (closet1[inputShelfIndex] == "ПУСТО") { closet1[inputShelfIndex] = inputItem; Console.WriteLine($"Вы добавили {inputItem} на полку {inputShelfIndex + 1}"); } else { Console.WriteLine($"Полка {inputShelfIndex + 1} занята"); } } Console.ReadKey(); Console.Clear(); }
Editor is loading...
Leave a Comment