コード例 #1
0
        /// <summary>
        /// This method calculates the result of all the operands in the OperandList
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        private void _calculate(double operand, string operatorString)
        {
            OperandList.Add(operand);
            if (OperandList.Count > 1)
            {
                switch (operatorString)
                {
                case "+":
                    this.Result = this.OperandList[0] + this.OperandList[1];
                    break;

                case "-":
                    this.Result = this.OperandList[0] - this.OperandList[1];
                    break;

                case "x":
                    this.Result = this.OperandList[0] * this.OperandList[1];
                    break;

                case "÷":
                    this.Result = this.OperandList[0] / this.OperandList[1];
                    break;
                }
                this.OperandList.Clear();
                this.OperandList.Add(this.Result);
                this.IsOperandTwo = false;
            }

            this.CurrentOperator = operatorString;
        }
コード例 #2
0
        /// <summary>
        /// This method displays the result in the ResultTextBox
        /// </summary>
        /// <returns></returns>
        private void _showResult(double operand)
        {
            Debug.WriteLine("OperandList Count: " + OperandList.Count);
            if (OperandList.Count > 0)
            {
                OperandList.Add(operand);
                this._calculate(operand, "=");
            }


            ResultTextBox.Text = this.Result.ToString();
        }
コード例 #3
0
        /// <summary>
        /// This method calculates the result of all the operands in the OperandList
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        private void _calculate(double operand, string operatorString)
        {
            OperandList.Add(operand);
            if (OperandList.Count > 1)
            {
                switch (operatorString)
                {
                case "+":
                    this.Result = this.OperandList[0] + this.OperandList[1];
                    break;

                case "-":
                    this.Result = this.OperandList[0] - this.OperandList[1];
                    break;

                case "x":
                    this.Result = this.OperandList[0] * this.OperandList[1];
                    break;

                case "÷":
                    try
                    {
                        if (this.OperandList[1] != 0)
                        {
                            this.Result = this.OperandList[0] / this.OperandList[1];
                        }
                        else
                        {
                            this.ResultTextBox.Text = "Can't be divisile by zero";
                        }
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine(exception.Message);
                    }

                    break;
                }
                this.OperandList.Clear();
                this.OperandList.Add(this.Result);
                this.IsOperandTwo = false;
            }

            this.CurrentOperator = operatorString;
        }
コード例 #4
0
ファイル: CalculatorForm.cs プロジェクト: waynepud/Lesson12B2
        /// <summary>
        /// This method calculates the result of all the operands in the operator list
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        private void _calculate(double operand, string operatorString)
        {
            OperandList.Add(operand);
            if (OperandList.Count > 1)
            {
                switch (operatorString) //Have to do multiply and divide for lab
                {
                case "+":
                    this.Result = this.OperandList[0] + this.OperandList[1];
                    break;

                case "-":
                    this.Result = this.OperandList[0] - this.OperandList[1];
                    break;
                }
            }
            this.CurrentOperator = operatorString;
        }
コード例 #5
0
        /// <summary>
        /// This method calculates the result of all the operands in the OperandList
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        private void _calculate(double operand, string operatorString)
        {
            OperandList.Add(operand);
            if (OperandList.Count > 1)
            {
                switch (operatorString)
                {
                case "+":
                    this.Result = this.OperandList[0] + this.OperandList[1];
                    break;

                case "-":
                    this.Result = this.OperandList[0] - this.OperandList[1];
                    break;

                case "x":
                    this.Result = this.OperandList[0] * this.OperandList[1];
                    break;

                case "÷":
                    if (this.OperandList[1] != 0)
                    {
                        this.Result = this.OperandList[0] / this.OperandList[1];
                    }
                    else
                    {
                        this.ResultTextBox.Text = "Cannot by divide by zero";
                    }

                    break;
                }
                this.OperandList.Clear();
                this.OperandList.Add(this.Result);
                this.IsOperandTwo = false;
            }
            this.CurrentOperator = operatorString;
        }