Exemple #1
0
 private void Divide()
 {
     if (workingString.Length != 0 && !Calculate.CheckForDoubleOperator(workingString))
     {
         result           = Calculate.calculate(workingString);
         workingString   += "/";
         lblDisplay3.Text = result.ToString();
         decimalPointed   = false;
         resulted         = false;
         newNumber        = true;
         Display();
     }
 }
Exemple #2
0
 //Triggered by the equals button.
 //Passes the input string to the calculate method in the utility class.
 //Displays the result in the main display label and clears the second one.
 private void SumResult()
 {
     if (workingString.Length != 0 && !Calculate.CheckForDoubleOperator(workingString))
     {
         result           = Calculate.calculate(workingString);
         lblDisplay1.Text = result.ToString();
         lblDisplay3.Text = "";
         workingString    = result.ToString();
         resulted         = true;
         if (!result.ToString().Contains("."))
         {
             decimalPointed = false;
         }
     }
 }
Exemple #3
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;
                }
            }
        }