예제 #1
0
 //Checks for operators in the string and, if so, calculates the sum and displays it in the
 //second display label.
 private void ButtonPress()
 {
     if (Calculate.CheckContainsOperators(workingString))
     {
         result           = Calculate.calculate(workingString);
         lblDisplay3.Text = result.ToString();
     }
     resulted  = false;
     newNumber = false;
     Display();
 }
예제 #2
0
        //If the equals button has been pressed the result is cleared and handles reset.
        //If not, the last digit or operator is deleted from the input. Checks are done to ensure
        //that multiple operators, decimal points etc can't be entered afterwards.
        //If the input is completely deleted then everything is cleared.
        private void Delete()
        {
            if (resulted == true)
            {
                lblDisplay1.Text = "";
                lblDisplay3.Text = "";
                workingString    = "";
                result           = 0;
                decimalPointed   = false;
                newNumber        = true;
            }
            else
            {
                if (workingString.Length > 0)
                {
                    workingString = workingString.Remove(workingString.Length - 1);

                    if (workingString.Length > 0 && Calculate.CheckContainsOperators(workingString) &&
                        !Calculate.CheckForDoubleOperator(workingString))
                    {
                        result           = Calculate.calculate(workingString);
                        lblDisplay3.Text = result.ToString();
                    }

                    if (workingString.Contains("."))
                    {
                        if (Calculate.CheckContainsOperators(workingString))
                        {
                            string[] splitString;
                            splitString = workingString.Split('+', '-', '*', '/');

                            if (splitString[splitString.Length - 1].Contains("."))
                            {
                                decimalPointed = true;
                            }
                            else
                            {
                                decimalPointed = false;
                            }
                        }
                        else
                        {
                            decimalPointed = true;
                        }
                    }
                    else
                    {
                        decimalPointed = false;
                    }

                    if (Calculate.CheckContainsOperators(workingString))
                    {
                        string[] splitString;
                        splitString = workingString.Split('+', '-', '*', '/');

                        if (splitString[splitString.Length - 1].Length == 0)
                        {
                            newNumber = true;
                        }
                    }

                    lblDisplay1.Text = "";
                    Display();
                }
                else
                {
                    lblDisplay1.Text = "";
                    lblDisplay3.Text = "";
                    workingString    = "";
                    result           = 0;
                    decimalPointed   = false;
                    newNumber        = true;
                }
            }
        }