Exemplo n.º 1
0
        public static void ThreeSideCalculation(Triangle Triangle1, Triangle Triangle2, ref bool Successful)
        {
            int  Triangle1Calculation = 7 - Triangle1.SideToCompare;
            int  Triangle2Calculation = 7 - Triangle2.SideToCompare;
            bool Triangle1Complete    = false;
            bool Triangle2Complete    = false;
            bool Done = false;

            if ((Triangle1Calculation == Triangle2Calculation) || (Triangle1Calculation == 3 && Triangle2Calculation == 6) || (Triangle1Calculation == 6 && Triangle2Calculation == 3))
            {
                Successful = false;
                return;
            }

            if (Triangle1Calculation == 0)
            {
                Triangle1Complete = true;
            }

            if (Triangle2Calculation == 0)
            {
                Triangle2Complete = true;
            }

            do
            {
                if ((Triangle1Calculation > Triangle2Calculation) && (Triangle2Calculation != 2))
                {
                    if (Triangle1Calculation == 6)
                    {
                        Triangle1.SideToCompare = 2;
                        DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle1Calculation = 4;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle1Calculation == 5)
                    {
                        Triangle1.SideToCompare = 3;
                        DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle1Calculation = 1;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle1Calculation == 4)
                    {
                        Triangle1.SideToCompare = 3;
                        DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle1Calculation = 0;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle1Calculation == 3)
                    {
                        Triangle1.SideToCompare = 2;
                        DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle1Calculation = 1;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle1Calculation == 2)
                    {
                        Triangle1.SideToCompare = 2;
                        DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle1Calculation = 0;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle1Calculation == 1)
                    {
                        Triangle1.SideToCompare = 1;
                        DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle1Calculation = 0;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle1Calculation == 0)
                    {
                        Triangle1Complete = true;
                    }
                }

                if ((Triangle2Calculation > Triangle1Calculation) || (Triangle2Calculation == 2))
                {
                    if (Triangle2Calculation == 6)
                    {
                        Triangle2.SideToCompare = 2;
                        DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle2Calculation = 4;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle2Calculation == 5)
                    {
                        Triangle2.SideToCompare = 3;
                        DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle2Calculation = 1;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle2Calculation == 4)
                    {
                        Triangle2.SideToCompare = 3;
                        DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle2Calculation = 0;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle2Calculation == 3)
                    {
                        Triangle2.SideToCompare = 2;
                        DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle2Calculation = 1;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle2Calculation == 2)
                    {
                        Triangle2.SideToCompare = 2;
                        DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle2Calculation = 0;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle2Calculation == 1)
                    {
                        Triangle2.SideToCompare = 1;
                        DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                        if (Successful == true)
                        {
                            Triangle2Calculation = 0;
                        }

                        else
                        {
                            return;
                        }
                    }

                    if (Triangle2Calculation == 0)
                    {
                        Triangle2Complete = true;
                    }
                }

                if (Triangle1Complete == true && Triangle2Complete == true)
                {
                    Done = true;
                }
            } while (Done == false);
        }
Exemplo n.º 2
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            int Completion      = 0;
            int SideToCalculate = 0;
            int SidesCalculated = 0;

            OutputBox.Text = "";

            bool SideCVisible = SideCInput.Visible;

            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    if (c.Visible)
                    {
                        string TextName    = c.Text;
                        string ControlName = c.Name;

                        if (TextName == "N" || TextName == "n")
                        {
                            Initialization.Init_SideToCalculate(ControlName, SideCVisible, ref SideToCalculate, ref Completion, ref SidesCalculated);

                            if (SideCVisible == false && Completion == 99)
                            {
                                OutputBox.AppendText("There is more than 1 variable entered. There needs to be only 1 N for this proportion." + Environment.NewLine);
                                return;
                            }
                            else if (SideCVisible == true && Completion == 99)
                            {
                                OutputBox.AppendText("There is more than 2 variable entered. There needs to be only 1 or 2 N(s) for this proportion." + Environment.NewLine);
                                return;
                            }
                        }

                        else if (!float.TryParse(TextName, out _))
                        {
                            OutputBox.AppendText(ControlName + " is in the incorrect format. Please correct and try again." + Environment.NewLine);
                            return;
                        }
                    }
                }
            }

            Triangle Triangle1 = new Triangle();
            Triangle Triangle2 = new Triangle();

            if (Completion != 99)
            {
                string SideAIn    = SideAInput.Text;
                string SideBIn    = SideBInput.Text;
                string SideCIn    = SideCInput.Text;
                string SideXIn    = SideXInput.Text;
                string SideYIn    = SideYInput.Text;
                string SideZIn    = SideZInput.Text;
                bool   Successful = false;

                Initialization.Init_SetTriangle(SideToCalculate, Triangle1, Triangle2, SideAIn, SideBIn, SideCIn, SideXIn, SideYIn, SideZIn, SideCVisible, ref Completion);

                if (Completion == 99)
                {
                    OutputBox.AppendText("There is a zero on one of the sides. Variable will be zero.");
                    return;
                }

                if (SideToCalculate <= 3)
                {
                    DoMath.Triangle1Calculation(Triangle1, Triangle2, ref Successful);

                    if (Successful == true)
                    {
                        OutputBox.AppendText("Triangle1 calculation is follows: " + Environment.NewLine +
                                             "Side A: " + Triangle1.SideA + Environment.NewLine +
                                             "Side B: " + Triangle1.SideB + Environment.NewLine);

                        if (SideCVisible == true)
                        {
                            OutputBox.AppendText("Side C: " + Triangle1.SideC + Environment.NewLine);
                        }
                    }
                }

                else if (SideToCalculate > 3 && SideToCalculate <= 6)
                {
                    DoMath.Triangle2Calculation(Triangle1, Triangle2, ref Successful);

                    if (Successful == true)
                    {
                        OutputBox.AppendText("Triangle2 calculation is follows: " + Environment.NewLine +
                                             "Side A: " + Triangle2.SideA + Environment.NewLine +
                                             "Side B: " + Triangle2.SideB + Environment.NewLine);

                        if (SideCVisible == true)
                        {
                            OutputBox.AppendText("Side C: " + Triangle2.SideC + Environment.NewLine);
                        }
                    }
                }

                else if (SideToCalculate == 7)
                {
                    DoMath.ThreeSideCalculation(Triangle1, Triangle2, ref Successful);

                    if (Successful == true)
                    {
                        OutputBox.AppendText("Triangle1 calculation is follows: " + Environment.NewLine +
                                             "Side A: " + Triangle1.SideA + Environment.NewLine +
                                             "Side B: " + Triangle1.SideB + Environment.NewLine +
                                             "Side C: " + Triangle1.SideC + Environment.NewLine +
                                             "--------------------" + Environment.NewLine);

                        OutputBox.AppendText("Triangle2 calculation is follows: " + Environment.NewLine +
                                             "Side A: " + Triangle2.SideA + Environment.NewLine +
                                             "Side B: " + Triangle2.SideB + Environment.NewLine +
                                             "Side C: " + Triangle2.SideC);
                    }

                    else
                    {
                        OutputBox.AppendText("Problem is insolvable.");
                    }
                }
            }
        }