Exemple #1
0
        void OnSelectOperator(object sender, EventArgs e)
        {
            Button button  = (Button)sender;
            string pressed = button.Text;


            if (((currentState == -2 || currentState == -1 || currentState == 1) && pressed == "%") ||
                pressed == "√" || pressed == "x²" || pressed == "1/x")
            {
                result = SimpleCalculator.Calculate(firstNumber, 1, pressed);

                this.resultText.Text = result.ToString();
                firstNumber          = result;
                currentState         = -1;
            }
            else if (currentState == 2)
            {
                result = SimpleCalculator.Calculate(firstNumber, secondNumber, mathOperator);

                this.resultText.Text = result.ToString();
                firstNumber          = result;
                currentState         = -1;
            }
            mathOperator = pressed;
            currentState = -2;
        }
Exemple #2
0
 protected void OnCalculate(Object sender, EventArgs e)
 {
     if (currentState == 2)
     {
         double result = SimpleCalculator.Calculate(value1, value2, mathOperator);
         resultText.Text = result.ToString();
         value1          = result;
         currentState    = -1;
     }
 }
 void OnCalculate(object sender, EventArgs e)
 {
     if (currentState == 2)
     {
         var result = SimpleCalculator.Calculate(firstNumber, secondNumber, mathOperator);
         this.resultText.Text = result.ToString();
         firstNumber          = result;
         currentState         = -1;
     }
 }
Exemple #4
0
        protected void OnCalculate(object sender, EventArgs e)
        {
            if (_currentState == 2)
            {
                var result = SimpleCalculator.Calculate(_firstNumber, _secondNumber, _mathOperator);

                this._resultText.Text = Math.Round(result, 5).ToString();                 //.ToString("N0");
                _firstNumber          = result;
                _currentState         = -1;
            }
        }
        private void OnCalculate(object sender, EventArgs e)
        {
            if (_currentState == 2)
            {
                var result = SimpleCalculator.Calculate(_firstNumber, _secondNumber, _mathOperator);

                LblResultText.Text = result.ToString("N0");
                _firstNumber       = result;
                _currentState      = -1;
            }
        }
        protected void OnCalculate(object sender, EventArgs e)
        {
            if (_currentState == 2)
            {
                var result = SimpleCalculator.Calculate(_firstNumber, _secondNumber, _mathOperator);

                LblResultText.Text = $" = {Math.Round(result, 5).ToString()}";                 //.ToString("N0");

                LblOperationText.Text = $"{_firstNumber} {_mathOperator} {_secondNumber}";
                _firstNumber          = result;
                _currentState         = -1;
            }
        }
Exemple #7
0
 static void Main(string[] args)
 {
     while (true)
     {
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Калькулятор со скобками и операциями +-*/ .Если хочешь получить нормальный результат ,то не дели на нуль.А так же, Ставь пробелы после каждой скобки-числа-оператора .Например : пиши не 2*(2+2), а пиши 2 * ( 2 + 2 ).Вы так же можете использовать константу P (записывать в верхнем регистре и на английском).");
         Console.Write("Введите выражение: ");
         SimpleCalculator calculator = new SimpleCalculator();
         string           expression = Console.ReadLine();
         Console.WriteLine(calculator.Calculate(expression));
         Console.ReadLine();
         Console.Clear();
     }
 }
Exemple #8
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Please enter calculation string");
            }
            List <IOperation> operations = new()
            {
                new AdditionOperation(),
                new SubstractionOperation(),
                new MultiplicationOperation(),
                new DivisionOperation()
            };
            ICalculator calculator = new SimpleCalculator(operations);

            calculator.Calculate(args[0]);
        }
    }
        //When we are ready to calculate the equation
        void OnCalculate(object sender, EventArgs e)
        {
            string eq = this.equation.Text;

            if (Regex.Matches(eq, @"[a-zA-Z]").Count > 1) //If there are any letters in the string it is not a math equation
            {
                this.resultText.Text = "Error: Invalid Equation; Letters are present";
                return;
            }
            int counter = 0;

            for (int i = 0; i < eq.Length; i++) //Check to make sure the same number of opening as closing parentheses
            {
                if (eq[i] == '(')
                {
                    counter++;
                }
                else if (eq[i] == ')')
                {
                    counter--;
                }
            }
            if (counter != 0) //If the counter != 0 then we know the number of closing or opening parantheses is off
            {
                this.resultText.Text = "Error: Invalid Equation; Wrong number of parenthesis";
                return;
            }
            double result = SimpleCalculator.Calculate(eq);

            if (result == -1)
            {
                this.resultText.Text = "Error: Invalid Equation; Wrong number of operators or arguments";
                return;
            }
            this.resultText.Text = result.ToString();
        }