static void Main(string[] args) { try { InputConverter inputConverter = new InputConverter(); CalculationEngine calculationEngine = new CalculationEngine(); //Read two operands from console and convert it to double WriteLine("Enter first operand: "); var firstNumber = inputConverter.ConvertToNumber(ReadLine()); WriteLine("Enter second operand: "); var secondNumber = inputConverter.ConvertToNumber(ReadLine()); //Read operator from console WriteLine("Enter operator: "); var operation = ReadLine(); //Perform the calculation and print thr result to console var result = calculationEngine.Calculate(operation, firstNumber, secondNumber); WriteLine(result); } catch (Exception exception) { WriteLine(exception.Message); } }
static void Main(string[] args) { try { InputConverter inputConverter = new InputConverter(); CalculatorEngine calculatorEngine = new CalculatorEngine(); Console.WriteLine("Enter two numbers followed by the operation you want to do(add, subtract, multiply or divide"); string firstInput = Console.ReadLine(); string secondInput = Console.ReadLine(); if (!String.IsNullOrWhiteSpace(firstInput) || !String.IsNullOrWhiteSpace(secondInput)) { double firstNumber = inputConverter.ConvertInputToNumeric(firstInput); double secondNumber = inputConverter.ConvertInputToNumeric(secondInput); string operation = Console.ReadLine(); double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber); Console.WriteLine(result); Console.ReadLine(); } else { Console.WriteLine("The number you have entered is null or empty."); Console.ReadLine(); } } catch (Exception exception) { Console.WriteLine(exception.Message); } }
static void Main(string[] args) { InputConverter inputConverter = new InputConverter(); CalculatorEngine calculatorEngine = new CalculatorEngine(); try { Console.Write("Enter First Number: "); double firstNumber = inputConverter.ConvertInputToNumberic(Console.ReadLine()); Console.Write("Enter Second Number: "); double secondNumber = inputConverter.ConvertInputToNumberic(Console.ReadLine()); Console.Write("Enter Operation: "); string operation = Console.ReadLine(); double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber); Console.WriteLine(result); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); } }
public static void Main(string[] args) { inputConverter = new InputConverter(); calculator = new Calculator(); GUI(); }
static void Main(string[] args) { try { InputConverter converter = new InputConverter(); CalculatorEngine calc = new CalculatorEngine(); double num1 = converter.ConvertInputToNumeric(Console.ReadLine()); string operation = Console.ReadLine(); double num2 = converter.ConvertInputToNumeric(Console.ReadLine()); double result = calc.Calculate(num1, operation, num2); Console.WriteLine(result); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { InputConverter converter = new InputConverter(); CalculatorEngine calculator = new CalculatorEngine(); Console.WriteLine("Welcome to the simple Calculator!"); Console.WriteLine("Please enter your first number"); double first = converter.ConvertInputToNumeric(Console.ReadLine()); Console.WriteLine("Please enter your second number"); double second = converter.ConvertInputToNumeric(Console.ReadLine()); Console.WriteLine("Now enter which operation you would like to do\n Addition: Press 1 \n Subtraction: Press 2\n Multiplication: Press 3\n Division: Press 4"); Int32.TryParse(Console.ReadLine(), out int operation); double result = calculator.Calculate(operation, first, second); Console.WriteLine("Your answer is: {0} ", result); }
static void Main(string[] args) { try { InputConverter inputConverter = new InputConverter(); CalculatorEngine calculatorEngine = new CalculatorEngine(); double firstNumber = inputConverter.converInputToNumeric(Console.ReadLine()); double secondNumber = inputConverter.converInputToNumeric(Console.ReadLine()); string operation = Console.ReadLine(); double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber); Console.WriteLine(result); } catch (Exception ex) { // in real world we would want to log this message Console.WriteLine(ex.Message); } }
static void Main(string[] args) { try { InputConverter inputConverter = new InputConverter(); CalculatorEngine calculatorEngine = new CalculatorEngine(); double firstNumber = inputConverter.ConvertInputToNum(Console.ReadLine()); double secondNumber = inputConverter.ConvertInputToNum(Console.ReadLine()); string operation = Console.ReadLine(); double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber); Console.WriteLine(result); } catch (Exception ex) { // Should log the exceptions Console.WriteLine(ex.Message); } }
static void Main(string[] args) { InputConverter inputConverter = new InputConverter(); CalculatorEngine calculatorEngine = new CalculatorEngine(); try { Console.Write("Enter the first number: "); double firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine()); Console.Write("Enter the Second number: "); double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine()); Console.Write("Enter The operator: "); string operation = Console.ReadLine(); double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber); Console.WriteLine($"The result is {result}"); } catch (Exception ex) { //TODO: Start logging exception. Console.WriteLine(ex.Message);; } }