Beispiel #1
0
        private void BtnMultiply_Click(object sender, EventArgs e)
        {
            //if Input call the Third Party library and perform the multiplication function
            if (CheckForInput(tbResult.Text))
            {
                if (!(plusButtonClicked && multiplyButtonClicked && minusButtonClicked && divisionButtonClicked))
                {
                    valueHolder = double.Parse(tbResult.Text);
                }
                else
                {
                    valueHolder = BasicMath.Multiplication(valueHolder, double.Parse(tbResult.Text));
                }

                tbResult.Clear();
                plusButtonClicked     = false;
                minusButtonClicked    = false;
                divisionButtonClicked = false;
                multiplyButtonClicked = true;
            }
            //if invalid input print error to user
            else
            {
                MessageBox.Show("Please enter valid input");
            }
            isTotal = false;
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello to Calc Test!");
     Console.WriteLine(string.Format("{0} + {1} = {2}", 20, 22, BasicMath.Sum(20, 22)));
     Console.WriteLine(string.Format("{0} - {1} = {2}", 50, 8, BasicMath.Difference(50, 8)));
     Console.WriteLine(string.Format("{0} * {1} = {2}", 7, 6, BasicMath.Multiplication(7, 6)));
     Console.WriteLine(string.Format("{0} / {1} = {2}", 420, 10, BasicMath.Division(420, 10)));
 }
        public void Should_True_One_Number_Multiplication()
        {
            //Arrange
            double oneNumber = 76;
            double multiplication;

            //Act
            multiplication = BasicMath.Multiplication(oneNumber);

            //Assert
            Assert.Equal(oneNumber, multiplication);
        }
        public void Should_True_Emtpy_Multiplication()
        {
            //Arrange
            double multiplication;
            double multiplicationNumber;

            //Act
            multiplicationNumber = 1;
            multiplication       = BasicMath.Multiplication();

            //Assert
            Assert.Equal(multiplicationNumber, multiplication);
        }
        public void Should_True_Two_Number_Multiplication()
        {
            //Arrange
            double oneNumber = 3;
            double twoNumber = 9;
            double multiplicationNumber;
            double multiplication;

            //Act
            multiplicationNumber = oneNumber * twoNumber;
            multiplication       = BasicMath.Multiplication(oneNumber, twoNumber);

            //Assert
            Assert.Equal(multiplicationNumber, multiplication);
        }
Beispiel #6
0
 private void BtnEquals_Click(object sender, EventArgs e)
 {
     /*depending on the last button to be clicked perform the correct operation
      * and output the result to the user
      */
     if (!(multiplyButtonClicked && minusButtonClicked &&
           plusButtonClicked && divisionButtonClicked) && CheckForInput(tbResult.Text))
     {
         total = double.Parse(tbResult.Text);
     }
     if (!double.TryParse(tbResult.Text, out double lastInput))
     {
         return;
     }
     if (plusButtonClicked)
     {
         total = BasicMath.Addition(valueHolder, lastInput);
     }
     else if (minusButtonClicked)
     {
         total = BasicMath.Subtraction(valueHolder, lastInput);
     }
     else if (multiplyButtonClicked)
     {
         total = BasicMath.Multiplication(valueHolder, lastInput);
     }
     else if (divisionButtonClicked)
     {
         if (BasicMath.Division(valueHolder, lastInput, out double setTotal))
         {
             total = setTotal;
         }
         else
         {
             MessageBox.Show("Error: Cannot Divide By Zero");
             return;
         }
     }
     //print result
     tbResult.Text = $"{total}";
     //reset calculator
     valueHolder       = 0;
     total             = 0;
     isTotal           = true;
     plusButtonClicked = minusButtonClicked = divisionButtonClicked = multiplyButtonClicked = false;
 }