Exemple #1
0
 static void Main(string[] args)
 {
     try
     {
         InputConverter   inputConverter = new InputConverter();
         CalculatorEngine calculator     = new CalculatorEngine();
         Console.WriteLine("Enter a number: ");
         double firstNumber = inputConverter.ConvertInputToNumber(Console.ReadLine());
         Console.WriteLine("Enter a number: ");
         double secondNumber = inputConverter.ConvertInputToNumber(Console.ReadLine());
         Console.WriteLine("Enter the operator: * + - /");
         string operation = Console.ReadLine();
         double result    = calculator.Calculate(operation, firstNumber, secondNumber);
         Console.WriteLine("{0} {1} {2} = {3} ", firstNumber, operation, secondNumber, result);
     }
     catch (Exception ex)
     {
         //throw new Exception("new error", ex);
         Console.WriteLine(ex.Message);
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                InputConverter inputConverter = new InputConverter();

                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }