Beispiel #1
0
        static void Main(string[] args)
        {
            int firstNumber = 0;
            int secondNumber = 0;
            string inputNumber = "";
            string inputNumber2 = "";


            Sign sign = Sign.Sum;
            firstNumber = inputNumber.CheckIntDigits();
            secondNumber = inputNumber2.CheckIntDigits();


            switch (sign)
            {
                case Sign.Sum:
                    {
                        int sum = Calculator.Sum(firstNumber, secondNumber);
                        Console.WriteLine("The sum is: " + sum.ToString());
                        break;
                    }
                case Sign.Subtract:
                    {
                        int difference = Calculator.Subtract(firstNumber, secondNumber);
                        Console.WriteLine("The difference is: " + difference.ToString());
                        break;
                    }
                case Sign.Multiply:
                    {
                        int product = Calculator.Multiply(firstNumber, secondNumber);
                        Console.WriteLine("The composition is: " + product.ToString());
                        break;
                    }
                case Sign.Divide:
                    {
                        int quotient = Calculator.Divide(firstNumber, secondNumber);
                        Console.WriteLine("The quotient is: " + quotient.ToString());
                        break;
                    }
                default:
                    {
                        Console.WriteLine("Enter a valid operator.");
                        break;
                    }
            }


            Calc calc = new Calc(1, 80);
            Calc calc1 = new Calc(100, 10);
            Calc calc2 = calc - calc1;
            calc2.Show();

            Console.ReadLine();
        }
Beispiel #2
0
 public static Calc operator -(Calc t1, Calc t2)
 {
     Calc calculator = new Calc();
     if ((t1.firstNumber > t2.firstNumber) && (t1.secondNumber > t2.secondNumber))
     {
         calculator.firstNumber = t1.firstNumber - t2.firstNumber;
         calculator.secondNumber = t1.secondNumber - t2.secondNumber;
         return calculator;
     }
     else if ((t1.firstNumber > t2.firstNumber) && (t1.secondNumber < t2.secondNumber))
     {
         calculator.firstNumber = t1.firstNumber - t2.firstNumber;
         calculator.secondNumber = t2.secondNumber - t1.secondNumber;
         return calculator;
     }
     else if ((t2.firstNumber > t1.firstNumber) && (t1.secondNumber < t2.secondNumber))
     {
         calculator.firstNumber = t2.firstNumber - t1.firstNumber;
         calculator.secondNumber = t2.secondNumber - t1.secondNumber;
         return calculator;
     }
     else if ((t2.firstNumber > t1.firstNumber) && (t1.secondNumber > t2.secondNumber))
     {
         calculator.firstNumber = t2.firstNumber - t1.firstNumber;
         calculator.secondNumber = t1.secondNumber - t2.secondNumber;
         return calculator;
     }
     else if ((t1.firstNumber == t2.firstNumber) && (t1.secondNumber < t2.secondNumber))
     {
         calculator.firstNumber = t1.firstNumber - t2.firstNumber;
         calculator.secondNumber = t2.secondNumber - t1.secondNumber;
         return calculator;
     }
     else if ((t1.firstNumber == t2.firstNumber) && (t1.secondNumber > t2.secondNumber))
     {
         calculator.firstNumber = t1.firstNumber - t2.firstNumber;
         calculator.secondNumber = t1.secondNumber - t2.secondNumber;
         return calculator;
     }
     else if ((t1.firstNumber > t2.firstNumber) && (t1.secondNumber == t2.secondNumber))
     {
         calculator.firstNumber = t1.firstNumber - t2.firstNumber;
         calculator.secondNumber = t2.secondNumber - t1.secondNumber;
         return calculator;
     }
     else
         calculator.firstNumber = t2.firstNumber - t1.firstNumber;
     calculator.secondNumber = t2.secondNumber - t1.secondNumber;
     return calculator;
 }
Beispiel #3
0
 public static Calc operator /(Calc t1, Calc t2)
 {
     Calc calculator = new Calc();
     if (t2.firstNumber == 0 || t2.secondNumber == 0) { throw new Exception("Divide by zero!"); }
     return new Calc(t1.firstNumber / t2.firstNumber, t1.secondNumber / t2.secondNumber);
 }