开发者

Please help me debug my calculator program [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I am trying to make a calculator. Whenever I put in something like 25 * 4 / 10 , it divides 25 by 4. Here is the part of the code I think might be the problem:

    private void button16_Click(object sender, RoutedEventArgs e)
    {

        string[] calCulation = CALCULATION.Text.Split('-', '+', '/', 'X');
        int numOfItems = calCulation.Length;
        int count = 1;
        char[] Arius = new char[Hey.Length];
        foreach(char words in Hey)
        {
            int outlie = 0;
            Arius[outlie] = words;
            outlie++;
        }
        decimal final = 0M;
        decimal[] calCulate = new decimal[numOfItems];
        int countfreak = 0;
        foreach (string word in calCulation)
        {

            calCulate[countfreak] = Convert.ToDecimal(word);
            countfreak++;
        }
        int counting = 1;
        int countinghey = 0;
        decimal final2 = calCulate[0];

        while(count < numOfItems){


            switch(Arius[countinghey])
            {
                case 'X':
                    /*
                        final2 += final * calCulate[counting -1];
                        final2 = final2 * calCulate[counting];
                     */
                    final2 = final2 * calCulate[counting];
                    break;
                case '-':


                        final2 = final2 - calCulate[counting];
                    break;
                case '+':


                        final2 = final2 + calCulate[counting];
                    break;
                case '/':


                        final2 = final2 / calCulate[counting];
                    break;
            }
             counting++;
             countinghey++;
             count++;

        }
   开发者_如何学运维     CALCULATION.Text = Convert.ToString(final2);
    }
    public bool Parshing(string value, string typee)
    {

        int hixty = value.Length;
        string six = value.Substring(hixty - 1, value.Length - hixty + 1);
        int lam;
        bool result = Int32.TryParse(six, out lam);
        if (result == true||six == "")
        {
            CALCULATION.Text += typee;
            Hey += typee;
        }
        else
        {
        }

        return result;
    }


Right off the bat, you are not splitting correctly.

string[] calCulation = CALCULATION.Text.Split('-', '+', '/', 'X');

given that you typed:

 25 * 4 / 10

you should change your split from 'X' to '*'

string[] calCulation = CALCULATION.Text.Split('-', '+', '/', '*');

You will further need to change your case statement. Or make sure your input is correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜