예제 #1
0
        private void btnExtraction_Click(object sender, EventArgs e)
        {
            FourOperations operations = new FourOperations();
            math_Op        op         = operations.Extraction;

            sonuc         = op(vs[0], vs[1]);
            txtSonuc.Text = "";
            txtSonuc.Text = sonuc.ToString();
        }
예제 #2
0
        private void btnDivide_Click(object sender, EventArgs e)
        {
            //delegate used
            FourOperations operations = new FourOperations();
            math_Op        op         = operations.Divide;

            sonuc         = op(vs[0], vs[1]);
            txtSonuc.Text = "";
            txtSonuc.Text = sonuc.ToString();
        }
예제 #3
0
        public Opdracht4()
        {
            /*
             * Opdracht 6.4:
             *   Schrijf een methode Calculate die als resultaat de uitkomst van een berekening geeft. De methode
             *   moet 3 parameters hebben:
             *      • De eerste parameter is voor het eerste getal. Dit getal kan ook decimalen bevatten
             *      • De tweede parameter is voor het tweede getal en kan ook decimalen bevatten.
             *      • De derde parameter is één enkel teken (char) dat aangeeft welke berekening uitgevoerd dient te worden:
             *
             *      ○ + : de som va de getallen
             *      ○ - : het verschil tussen beide getallen
             *      ○ * : het product van beide getallen
             *      ○ / : het quotiënt (eerste getal gedeeld door tweede getal; denk eraan: delen door nul blijft flauwekul)
             *      ○ % : het restant van eerste getal gedeeld door tweede getal (delen door nul is???)
             */


BACKTOTOP:
            double firstNumber, secondNumber;

            Console.Write("\n\tEnter your 'first number': ");
            firstNumber = Convert.ToDouble(Console.ReadLine());
            Console.Write("\n\tEnter your 'second number': ");
            secondNumber = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("");

MAKEYOURCHOICE:
            Console.Write(" Make your choice? (Addition:'1' || Subtraction:'2' || Multiplication:'3' || Division:'4' || Module:'5') => ");
            char userChoice = Convert.ToChar(Console.ReadLine());

            switch (userChoice)
            {
            case '1':
                FourOperations DoAddition     = new FourOperations();
                double         additionResult = DoAddition.SumNumbers(firstNumber, secondNumber);
                Console.WriteLine("\n\tAddition Result: {0}", additionResult);
                break;

            case '2':
                FourOperations DoSubtraction     = new FourOperations();
                double         subtractionResult = DoSubtraction.SubtractNumbers(firstNumber, secondNumber);
                Console.WriteLine("\n\tSubtraction Result: {0}", subtractionResult);
                break;

            case '3':
                FourOperations DoMultiplication     = new FourOperations();
                double         multiplicationResult = DoMultiplication.MultiplyNumbers(firstNumber, secondNumber);
                Console.WriteLine("\n\tMutiplication Result: {0}", multiplicationResult);
                break;

            case '4':
                FourOperations DoDivision     = new FourOperations();
                double         divisionResult = DoDivision.DevideNumbers(firstNumber, secondNumber);
                Console.WriteLine("\n\tDivision Result: {0}", divisionResult);
                break;

            case '5':
                FourOperations FindModule   = new FourOperations();
                double         ModuleResult = FindModule.FindModuleOfNumbers(firstNumber, secondNumber);
                Console.WriteLine("\n\tDivision Result: {0}", ModuleResult);
                break;

            default:
                Console.Clear();
                Console.WriteLine("You entered an invalid value! Please enter a valid value.\n");
                goto MAKEYOURCHOICE;
            }

TRYAGAIN:
            Console.Write("\nWould you like to do another four operation? (YES:'y' or NO:'n') => ");
            string doAnotherOperation = Console.ReadLine();

            if (doAnotherOperation == "y" || doAnotherOperation == "Y" || doAnotherOperation == "YES" || doAnotherOperation == "yes")
            {
                Console.Clear();
                goto BACKTOTOP;
            }
            else if (doAnotherOperation == "n" || doAnotherOperation == "N" || doAnotherOperation == "NO" || doAnotherOperation == "no")
            {
                Console.WriteLine("Bye bye ...");
                Console.WriteLine("\nPress any key to close the Console Window!");
            }
            else
            {
                Console.WriteLine("You entered an invalid value! Please try again.");
                goto TRYAGAIN;
            }

            Console.ReadKey();
        }