Exemplo n.º 1
0
        private void EqualsButton_Click(object sender, RoutedEventArgs e)
        {
            if (!calculation.IsEvaluable)
            {
                ResultDisplay.Text = "No operator defined, try again!";
                return;
            }

            if (string.IsNullOrEmpty(number))
            {
                ResultDisplay.Text = "There is nothing to compute.";
                return;
            }

            calculation.SecondNumber = Int32.Parse(number);
            number = string.Empty;

            double result = calculation.GetResult();

            if (calculation.Operator.Equals(ArithmeticOperator.Division) && result == -1)
            {
                ResultDisplay.Text = "Can not divide by zero";
            }
            else
            {
                ResultDisplay.Text = result.ToString();
            }

            calculation.Clean();
            cleanMessageDisplay = true;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ConsoleReader consoleReader = new ConsoleReader();
            Calculation   calculation   = new Calculation();

            Console.WriteLine(calculation.GetResult(consoleReader.GetFirstNumber(),
                                                    consoleReader.GetSecondNumber(),
                                                    consoleReader.GetOperator()));
            Console.ReadKey();
        }