Не могу понять в чём дело. Не отображается значение - C#

Узнай цену своей работы

Формулировка задачи:

Привет! Иногда не отображается значение "Полный дом!" и я не знаю почему. Подскажите пожалуйста. Вот:
        static void Game()
        {
            Random random = new Random();
            int[] slot = new int[5];
 
            do
            {
                Console.Clear();
 
                for (int i = 0; i < slot.Length; ++i)
                {
                    slot[i] = random.Next(1, 3);
                    Console.Write("{0} ", slot[i]);
                }
                Console.WriteLine();
 
                int a = 0;
                int b = 0;
 
                // Комбинации
                #region Пятёрка
 
                for (int c = 0; c < slot.Length; ++c)
                {
                    for (int d = 0; d < slot.Length; ++d)
                    {
                        if (slot[c] == slot[d])
                        {
                            ++a;
                        }
                    }
                    if (a == 5) break;
                    else a = 0;
                }
 
                if (a == 5)
                {
                    Console.WriteLine("Пятёрка!");
                    continue;
                }
 
                #endregion
 
                #region Четвёрка
 
                for (int c = 0; c < slot.Length; ++c)
                {
                    for (int d = 0; d < slot.Length; ++d)
                    {
                        if (slot[c] == slot[d])
                        {
                            ++a;
                        }
                    }
                    if (a == 4) break;
                    else a = 0;
                }
 
                if (a == 4)
                {
                    Console.WriteLine("Четвёрка!");
                    continue;
                }
 
                #endregion
 
                #region Полный дом
 
                for (int c = 0; c < slot.Length; ++c)
                {
                    for (int d = 0; d < slot.Length; ++d)
                    {
                        if (slot[c] == slot[d])
                        {
                            ++a;
                        }
                    }
 
                    if (a == 3)
                    {
                        for (int e = 0; e < slot.Length; ++e)
                        {
                            for (int f = 0; f < slot.Length; ++f)
                            {
                                if (((slot[e] != slot[c] || (slot[f] != slot[c])) && (slot[e] == slot[f])))
                                {
                                    ++b;
                                }
                            }
                            if (b == 2) break;
                        }
                    }
                    break;
                }
 
                if (a == 3 && b == 2)
                {
                    Console.WriteLine("Полный дом!");
                    continue;
                }
 
                #endregion
            } while (Console.ReadKey().Key == ConsoleKey.Enter);
        }
Эврика! КАК?! Не могу понять! Перетыкал и вот получилось! Совсем с ума сойдёшь, пока нужные break'и в нужные места поставишь. Не заметил ни одного пустого места.
                #region Полный дом
 
                for (int c = 0; c < slot.Length; ++c)
                {
                    for (int d = 0; d < slot.Length; ++d)
                    {
                        if (slot[c] == slot[d])
                        {
                            ++a;
                        }
                    }
 
                    if (a == 3)
                    {
                        for (int e = 0; e < slot.Length; ++e)
                        {
                            for (int f = 0; f < slot.Length; ++f)
                            {
                                if (((slot[e] != slot[c] || (slot[f] != slot[c])) && (slot[e] == slot[f])))
                                {
                                    ++b;
                                }
                            }
                            if (b == 2) break;
                            else b = 0;
                        }
                        break;
                    }
                    else a = 0;
 
                }
 
                if (a == 3 && b == 2)
                {
                    Console.WriteLine("Полный дом!");
                    continue;
                }
 
                #endregion

Решение задачи: «Не могу понять в чём дело. Не отображается значение»

textual
Листинг программы
        static Random rnd = new Random();
        static int[] array = new int[5];
        static void Game()
        {
            do
            {
                for(int i = 0; i < array.Length; i++)
                {
                    Console.Write((array[i] = rnd.Next(1, 3)) + " ");
                }
                int count = array.Count(x => x == 1);
                Console.WriteLine(count == 5 || count == 0 ? "= 5" : count == 4 || count == 1 ? "= 4" : "= full house");
            } while(Console.ReadKey(true).Key == ConsoleKey.Enter);
        }
        static void Main(string[] args)
        {
            Game();
            Console.ReadKey(true);
        }

Оцени полезность:

9   голосов , оценка 3.667 из 5
Похожие ответы