Esempio n. 1
0
        private void calculateButton_Click(object sender, EventArgs e)
        {
            string input = textBox.Text;

            if (Brackets.BracketsBalanced(input))
            {
                if (Brackets.OperationNextToBracket(input))
                {
                    if (Brackets.BracketsEmpty(input))
                    {
                        MessageBox.Show("The brackets are empty!");
                    }
                    else
                    {
                        string answer = Calculation.Calculate(input);
                        textBox.Text = answer;
                    }
                }
                else
                {
                    MessageBox.Show("Please add an operation between the number and bracket.");
                }
            }
            else
            {
                MessageBox.Show("A bracket is missing.");
            }
        }
Esempio n. 2
0
        private void Form1_Calculate(object sender, EventArgs e)
        {
            foreach (Match m in Regex.Matches(form1.textBox1.Text, @"([+-]?\d*[.,]?\d+)([-+*/])([+-]?\d*[.,]?\d+)"))
            {
                double.TryParse(m.Groups[1].Value.Replace('.', ','), out double number1);
                char.TryParse(m.Groups[2].Value, out char symbol);
                double.TryParse(m.Groups[3].Value.Replace('.', ','), out double number2);

                try
                {
                    form1.textBox1.Text = calc.Calculate(number1, number2, symbol).ToString();
                }
                catch (AppException ex)
                {
                    form1.textBox1.Text     = ex.Message;
                    form1.textBox1.KeyDown += TextBox1_KeyDown;
                }
            }
        }
Esempio n. 3
0
 public IResult Calculate(Request request)
 {
     return(_calculation.Calculate(request));
 }
Esempio n. 4
0
 private void ButtonEquals_Click(object sender, EventArgs e)
 {
     calculation.Calculate();
 }