| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 2014 人关注过本帖
标题:计算器怎么进行二次计算
只看楼主 加入收藏
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
结帖率:0
  已结贴   问题点数:20  回复次数:6   
计算器怎么进行二次计算
        private string a=null;
        private string b=null;
        private double c=0;
        private string sign=null;
        private bool dian=false;
        

        public Form1()
        {
            InitializeComponent();
        }
        //跟按钮的单击事件关联的方法
        private void button3_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "0";
            }
            else if (a == null)
            {
                a = "0";
            }
            textBox1.Text = a;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "1";
            }
            else if (a == null)
            {
                a = "1";
            }
            textBox1.Text = a;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (dian == false)
            {
                dian = true;
                if (a != null)
                {
                    a = a + ".";
                }
                else
                {
                    a = "0.";
                }
                textBox1.Text = a;
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "+";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if(sign =="+")
            {
                c = Convert.ToDouble(a) + Convert.ToDouble(b);
            }
            if(sign =="-")
            {
                c = Convert.ToDouble(b) - Convert.ToDouble(a);
            }
            if (sign == "*")
            {
                c = Convert.ToDouble(a) * Convert.ToDouble(b);
            }
            if (sign == "/")
            {
                c = Convert.ToDouble(b) / Convert.ToDouble(a);
            }
            textBox1.Text = Convert.ToString(c);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "2";
            }
            else if (a == null)
            {
                a = "2";
            }
            textBox1.Text = a;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "3";
            }
            else if (a == null)
            {
                a = "3";
            }
            textBox1.Text = a;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "4";
            }
            else if (a == null)
            {
                a = "4";
            }
            textBox1.Text = a;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "5";
            }
            else if (a == null)
            {
                a = "5";
            }
            textBox1.Text = a;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "6";
            }
            else if (a == null)
            {
                a = "6";
            }
            textBox1.Text = a;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "7";
            }
            else if (a == null)
            {
                a = "7";
            }
            textBox1.Text = a;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "8";
            }
            else if (a == null)
            {
                a = "8";
            }
            textBox1.Text = a;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "9";
            }
            else if (a == null)
            {
                a = "9";
            }
            textBox1.Text = a;
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "-";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "*";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "/";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button17_Click(object sender, EventArgs e)
        {
            textBox1.Text = "0";
            c = 0;
            a = null;
            b = null;
            dian = false;
            sign = null;
        }
搜索更多相关主题的帖子: 计算器  private  public  double  false  
2015-12-22 12:54
afdoa83
Rank: 4
等 级:业余侠客
威 望:7
帖 子:43
专家分:262
注 册:2012-7-31
  得分:10 
假设只做加法
按钮13应该是加号,按钮12应该是等于把。
1.当第一次按等于计算后,没有初始化sign,在按加号时由于sign没有初始化,按钮13不执行。
2.当第一次按等于计算后,a的赋值不是和。不注意这里会结果错误。
2015-12-22 13:22
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
  得分:0 
回复 2楼 afdoa83
我还是搞不懂能不能帮我弄一下
附件: 您没有浏览附件的权限,请 登录注册
2015-12-22 14:00
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:367
帖 子:12740
专家分:49749
注 册:2012-10-18
  得分:10 
回复 3楼 即使你在
你这个例子能进行二次计算啊

我不太明白你想做什么  或者你的二次计算是什么意思

DO IT YOURSELF !
2015-12-22 14:22
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
  得分:0 
回复 4楼 wp231957
就是覆盖前面的结果,进行下一次计算
2015-12-22 14:37
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:367
帖 子:12740
专家分:49749
注 册:2012-10-18
  得分:0 
不是你自己的代码吗    点 CE  按钮就清除了啊

DO IT YOURSELF !
2015-12-22 14:38
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
  得分:0 
回复 6楼 wp231957
这个我知道,我的意思是不要用CE这个键,像我们平常计算器可以覆盖,可以叠加
2015-12-22 14:41







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028365 second(s), 9 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved