Ejemplo n.º 1
0
        public void Run()
        {
            bool close = false;

            while (!close)
            {
                Console.WriteLine("To exit, please press 0....");
                var choice = Console.ReadLine();

                switch (choice)
                {
                case "0":
                    close = true;
                    break;

                default:
                    Console.WriteLine("Enter first number");
                    var res1 = Console.ReadLine();
                    var num1 = Convert.ToInt32(res1);

                    Console.WriteLine("Enter next number");
                    var res2 = Console.ReadLine();
                    var num2 = Convert.ToInt32(res2);

                    Console.WriteLine("What operation (Add/Sub/Mul/Div)?");
                    var op = Console.ReadLine();

                    Console.WriteLine($"Result: {_math.Calculate(num1, num2, op)}");
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public async Task Run()
        {
            _logger.LogDebug("App Started......");
            //_logger.LogDebug(_appSettings.ToString());
            bool quit = false;

            while (!quit)
            {
                _logger.LogDebug("Running.....");
                Console.WriteLine("If you would like to calculate, please press 1, else press 0 to exit");
                var choice = Console.ReadLine();

                if (choice == "0")
                {
                    _logger.LogDebug("Exit has been pressed.....");
                    quit = true;
                }
                else
                {
                    Console.WriteLine("Enter first number");
                    var res1 = Console.ReadLine();
                    var num1 = Convert.ToInt32(res1);
                    _logger.LogDebug($"First number entered: {num1}");

                    Console.WriteLine("Enter next number");
                    var res2 = Console.ReadLine();
                    var num2 = Convert.ToInt32(res2);
                    _logger.LogDebug($"Second number entered: {num2}");

                    Console.WriteLine("What operation (Add/Sub/Mul/Div)?");
                    var op = Console.ReadLine();
                    _logger.LogDebug($"Operation entered: {op}");

                    Console.WriteLine($"Result: {_math.Calculate(num1, num2, op)}");
                    _logger.LogDebug($"Result: {_math.Calculate(num1, num2, op)}");
                }
            }


            await Task.CompletedTask;
        }