Ejemplo n.º 1
0
        // class contains all mathematical operation-related functions

        public static string getFinalAns(List <string> input)
        {
            // loop through final formatted list
            // pass numbers and operator into calculate function

            List <string> formattedList = ProcessInput.formatInput(input);

            for (int i = 0; i < formattedList.Count; i++)
            {
                if (formattedList[i].Equals("^"))
                {
                    formattedList = calculate(formattedList, i);
                    --i;
                }
            }

            for (int i = 0; i < formattedList.Count; i++)
            {
                if (CheckInput.timesDivOrMod(formattedList[i]))
                {
                    formattedList = calculate(formattedList, i);
                    --i;
                }
            }

            for (int i = 0; i < formattedList.Count; i++)
            {
                if (CheckInput.plusOrMinus(formattedList[i]))
                {
                    formattedList = calculate(formattedList, i);
                    --i;
                }
            }
            return("" + double.Parse(formattedList[0]));
        }
Ejemplo n.º 2
0
        private static bool hasNonDouble(string input)
        {
            // check whether there is a non-double value in input

            List <string> numList = ProcessInput.toNumList(input);

            foreach (string value in numList)
            {
                if (!(isDouble(value)))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static bool divZero(List <string> inputList)
        {
            // check whether there is a "division by 0" expression in input

            List <string> formattedList = ProcessInput.formatInput(inputList);

            for (int i = 0; i < formattedList.Count; i++)
            {
                if ((formattedList[i].Equals("/") || formattedList[i].Equals("%")) &&
                    double.Parse(formattedList[i + 1]) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        private void equalsBtn_Click(object sender, EventArgs e)
        {
            // print result in textbox based on current input
            // change state of textbox content based on result of calculation

            List <string> inputList = ProcessInput.splitInput(ioBox.Text);

            if (CheckInput.isInvalid(ioBox.Text, inputList))
            {
                ioBox.Text = "Invalid double";
                isErrMsg   = true;
            }
            else if (CheckInput.divZero(inputList))
            {
                ioBox.Text = "Division by zero";
                isErrMsg   = true;
            }
            else
            {
                ioBox.Text = Operations.getFinalAns(inputList);
                isAns      = true;
            }
        }