标题:c#新手计算器求助!!!
取消只看楼主
伍嚎
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-4-11
结帖率:100%
已结贴  问题点数:20 回复次数:2 
c#新手计算器求助!!!
这是我用窗体编的计算器代码,计算结果都不对,求解释,有附件(只编到计算的...)
ex4.rar (38.16 KB)

namespace ex4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            textBox1.Text = textBox1.Text + btn.Text;
            
        }
        string a ;
        string f;
        int num1;

        private void button14_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            a = textBox1.Text;
            num1 = Convert.ToInt32(a);
            textBox1.Text = "";
            f = btn.Text;
            


        }
        
        private void button18_Click(object sender, EventArgs e)
        {
            if (f == "+")
            {
                int c = num1 + Convert.ToInt32(a);
                textBox1.Text = Convert.ToString(c);
            }
            else if (f == "-")
            {
                int c = num1 - Convert.ToInt32(a);
                textBox1.Text = Convert.ToString(c);
            }
            else if (f == "*")
            {
                int c = num1 * Convert.ToInt32(a);
                textBox1.Text = Convert.ToString(c);
            }
            else if (f == "/")
            {
                int c = num1 / Convert.ToInt32(a);
                textBox1.Text = Convert.ToString(c);
            }

        }  
    }
}
搜索更多相关主题的帖子: 计算器 
2011-04-28 23:39
伍嚎
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-4-11
得分:0 
回复 4楼 qq1023569223
木有办法啊,刚学个皮毛老师就叫做计算器了......
2011-04-30 17:43
伍嚎
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-4-11
得分:0 
回复 9楼 Snow_Pu
不行,也在为这个发愁呢.....
2011-05-13 21:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-338303-1-1.html




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

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