Ejemplo n.º 1
0
        private void equalButton_Click(object sender, RoutedEventArgs e)
        {
            double secNum = 0;

            if (double.TryParse(resultLabel.Content.ToString(), out secNum))
            {
                switch (op)
                {
                case Operator.Addition:
                {
                    result = Arithmetic.Add(lastNum, secNum);
                    break;
                }

                case Operator.Division:
                {
                    result = Arithmetic.Div(lastNum, secNum);
                    break;
                }

                case Operator.Multiplication:
                {
                    result = Arithmetic.Mult(lastNum, secNum);
                    break;
                }

                case Operator.Subtraction:
                {
                    result = Arithmetic.Sub(lastNum, secNum);
                    break;
                }
                }
                resultLabel.Content = result.ToString();
            }
        }
Ejemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button obj   = sender as Button;
            string strip = obj.Content.ToString();

            if (strip[0] >= '0' && strip[0] <= '9')
            {
                textbox1.Text = textbox1.Text + strip;
            }
            else if (strip[0] == '-' || strip[0] == '+' || strip[0] == '*' || strip[0] == '/')
            {
                operation     = strip[0];
                ip1           = Convert.ToInt32(textbox1.Text);
                textbox1.Text = "";
            }
            else if (strip[0] == '=')
            {
                ip2           = Convert.ToInt32(textbox1.Text);
                textbox1.Text = "";


                if (operation == '+')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.Add().ToString();
                }
                else if (operation == '-')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.Sub().ToString();
                }
                else if (operation == '*')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.mul().ToString();
                }
                else if (operation == '/')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.div().ToString();
                }
            }
        }