public void DisplayAnswerForAllOperators(NumberContainer container)
 {
     Console.WriteLine(container.Number1 + " + " + container.Number2 + " = " + container.Result1);
     Console.WriteLine(container.Number1 + " - " + container.Number2 + " = " + container.Result2);
     Console.WriteLine(container.Number1 + " * " + container.Number2 + " = " + container.Result3);
     Console.WriteLine(container.Number1 + " / " + container.Number2 + " = " + container.Result4);
     Console.WriteLine(container.Number1 + " Mod " + container.Number2 + " = " + container.Result5);
 }
示例#2
0
        public void TimesTable(NumberContainer container)
        {
            int i = 0;

            while (i < 11)
            {
                container.Result = container.Number1 * i;
                Console.WriteLine(container.Number1 + " * " + i + " = " + container.Result);
                i++;
            }
        }
示例#3
0
        //Write a C# Sharp program to that takes three numbers(x,y,z) as input and print the output of (x+y).z and x.y + y.z. Go to the editor
        //Test Data:
        //Enter first number - 5
        //Enter second number - 6
        //Enter third number - 7

        //Expected Output:
        //Result of specified numbers 5, 6 and 7, (x+y).z is 77 and x.y + y.z is 72



        public static void Main(string[] args)
        {
            NumberContainer container     = new NumberContainer();
            Math            doMath        = new Math();
            UserInterface   userInterface = new UserInterface();

            userInterface.GatherNumbers(container);

            doMath.EquationOne(container);
            doMath.EquationTwo(container);


            userInterface.DisplayEquationOne(container);
            userInterface.DisplayEquationTwo(container);
        }
示例#4
0
 public double MultiplyThreeNumbers(NumberContainer container)
 {
     container.Result = container.Number1 * container.Number2 * container.Number3;
     return(container.Result);
 }
示例#5
0
        public double EquationTwo(NumberContainer container)
        {
            container.Result2 = (container.Number1 * container.Number2) + (container.Number2 * container.Number3);

            return(container.Result2);
        }
示例#6
0
        public double EquationOne(NumberContainer container)
        {
            container.Result1 = (container.Number1 + container.Number2) * container.Number3;

            return(container.Result1);
        }
示例#7
0
        public double AverageFourNumbers(NumberContainer container)
        {
            container.Result = (container.Number1 + container.Number2 + container.Number3 + container.Number4) / 4;

            return(container.Result);
        }
示例#8
0
 public double ModTwoNumbers(NumberContainer container)
 {
     container.Result5 = container.Number1 % container.Number2;
     return(container.Result);
 }
示例#9
0
 public double DivideTwoNumbers(NumberContainer container)
 {
     container.Result4 = container.Number1 / container.Number2;
     return(container.Result);
 }
示例#10
0
 public double MultiplyTwoNumbers(NumberContainer container)
 {
     container.Result3 = container.Number1 * container.Number2;
     return(container.Result);
 }
示例#11
0
 public double SubtractTwoNumbers(NumberContainer container)
 {
     container.Result2 = container.Number1 - container.Number2;
     return(container.Result);
 }
示例#12
0
 public double AddTwoNumbers(NumberContainer container)
 {
     container.Result1 = container.Number1 + container.Number2;
     return(container.Result);
 }
        public void GatherNumbers(NumberContainer container)
        {
            var  done  = false;
            bool valid = false;

            while (valid == false)
            {
                Console.WriteLine("enter your first number");
                var stringNumber1 = Console.ReadLine();

                if (!double.TryParse(stringNumber1, out double n1))
                {
                    Console.WriteLine("not an int");
                }
                else
                {
                    container.Number1 = n1;
                    valid             = true;
                }
            }

            bool valid2 = false;

            while (valid2 == false && done == false)
            {
                Console.WriteLine("enter your second number or enter done");
                var stringNumber2 = Console.ReadLine();

                if (stringNumber2 == "done")
                {
                    done = true;
                }
                else
                {
                    if (!double.TryParse(stringNumber2, out double n2))
                    {
                        Console.WriteLine("not an int");
                    }
                    else
                    {
                        container.Number2 = n2;
                        valid2            = true;
                    }
                }
            }

            bool valid3 = false;

            while (valid3 == false && done == false)
            {
                Console.WriteLine("enter your third number or enter done.");
                var stringNumber3 = Console.ReadLine();

                if (stringNumber3 == "done")
                {
                    done = true;
                }
                else
                {
                    if (!double.TryParse(stringNumber3, out double n3))
                    {
                        Console.WriteLine("not an int");
                    }
                    else
                    {
                        container.Number3 = n3;
                        valid3            = true;
                    }
                }
            }

            bool valid4 = false;

            while (valid4 == false && done == false)
            {
                Console.WriteLine("enter your fourth number or enter done.");
                var stringNumber4 = Console.ReadLine();

                if (stringNumber4 == "done")
                {
                    done = true;
                }
                else
                {
                    if (!double.TryParse(stringNumber4, out double n4))
                    {
                        Console.WriteLine("not an int");
                    }
                    else
                    {
                        container.Number4 = n4;
                        valid4            = true;
                    }
                }
            }
        }
 public void DisplayEquationTwo(NumberContainer container)
 {
     Console.WriteLine(container.Number1 + "*" + container.Number2 + " + " + container.Number2 + "*" + container.Number3 + " equals " + container.Result2);
 }
 public void DisplayEquationOne(NumberContainer container)
 {
     Console.WriteLine("(" + container.Number1 + "+" + container.Number2 + ")*" + container.Number3 + " equals " + container.Result1);
 }
 public void DisplayAverageOfFourNumbers(NumberContainer container)
 {
     Console.WriteLine("The average of " + container.Number1 + "," + container.Number2 + "," + container.Number3
                       + " and " + container.Number4 + " is " + container.Result);
 }