public void DisplayAnswer(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
        //Write a C# Sharp program that takes a number as input and print its multiplication table. Go to the editor
        //Test Data:
        //Enter the number: 5
        //Expected Output:
        //5 * 0 = 0
        //5 * 1 = 5
        //5 * 2 = 10
        //5 * 3 = 15
        //....
        //5 * 10 = 50



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

            userInterface.GatherNumbers(container);

            doMath.TimesTable(container);
        }
Пример #3
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++;
            }
        }
        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;
                    }
                }
            }
        }
Пример #5
0
 public double MultiplyThreeNumbers(NumberContainer container)
 {
     container.Result = container.Number1 * container.Number2 * container.Number3;
     return(container.Result);
 }
Пример #6
0
 public double ModTwoNumbers(NumberContainer container)
 {
     container.Result5 = container.Number1 % container.Number2;
     return(container.Result);
 }
Пример #7
0
 public double DivideTwoNumbers(NumberContainer container)
 {
     container.Result4 = container.Number1 / container.Number2;
     return(container.Result);
 }
Пример #8
0
 public double MultiplyTwoNumbers(NumberContainer container)
 {
     container.Result3 = container.Number1 * container.Number2;
     return(container.Result);
 }
Пример #9
0
 public double SubtractTwoNumbers(NumberContainer container)
 {
     container.Result2 = container.Number1 - container.Number2;
     return(container.Result);
 }
Пример #10
0
 public double AddTwoNumbers(NumberContainer container)
 {
     container.Result1 = container.Number1 + container.Number2;
     return(container.Result);
 }