请帮我调试我的计算器程序

发布于 2024-11-30 20:14:51 字数 2180 浏览 0 评论 0原文

我正在尝试制作一个计算器。每当我输入类似 25 * 4 / 10 的内容时,它都会将 25 除以 4。这是我认为可能存在问题的代码部分:

    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;
    }

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;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

节枝 2024-12-07 20:14:51

马上,你就没有正确分裂。

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

鉴于您输入:

 25 * 4 / 10

您应该将拆分从“X”更改为“*”

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

您还需要更改案例声明。或者确保您的输入正确。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文