首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

C#加法器的有关问题

2012-12-24 
C#加法器的问题请问IF(ca+b)答对了我就加一分如何实现呢?我用过 if(ca+b){int sumfor(n0n100n++)

C#加法器的问题
请问
IF(c==a+b)答对了我就加一分如何实现呢?
我用过 
if(c==a+b)
{int sum;
for(n=0;n<100;n++)
sum+=n
string s=sum.TOstring();
label5.s=sum;
}
行不通!



源程序如下:
   private void Form1_Load(object sender, EventArgs e)
        {
            int n;
            Random my = new Random();
            n=my.Next(5);
            label1.Text = n.ToString();//为了把label1转换为字符串
            n = my.Next(10);
            label3.Text = n.ToString();
            

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            
            if (!(char.IsDigit(e.KeyChar) == true)|| e.KeyChar == 8)
                e.Handled = true;
            if (e.KeyChar == 13 )
            {
                int n=0;
                
                if (textBox1.Text == "")
                {
                    MessageBox.Show("未输入答案");
                    return;
                }
                int a, b, c;
                a = int.Parse(label1.Text);
                b = int.Parse(label3.Text);
                c = int.Parse(textBox1.Text);
                
                if (c == a + b)
                {
                    MessageBox.Show("真聪明答对了");
                    Form1_Load(null, null);//清零
                    textBox1.Text = "";


                    textBox1.Focus();
                    
                    
                   
                   
                   

                }
                else if (c != a + b)
                {
                   
                    Form1_Load(null, null);//清零
                    textBox1.Text = "";
                    textBox1.Focus();
                
                }

                else
                {
                    MessageBox.Show ("答错了,重试一次");
                    textBox1.Text = "";
                    textBox1.Focus();
                }
              
            }
        }

[解决办法]
写的真丑
[解决办法]


 public partial class Form1 : Form
    {
        int m_FirstValue = 0;
        int m_SecondValue = 0;
        public Form1()
        {
            InitializeComponent();
            LoadValue();
        }

        private void LoadValue()
        {
            Random my = new Random(DateTime.Now.Millisecond);


            m_FirstValue = my.Next(5);
            lbFirst.Text = m_FirstValue.ToString();
            m_SecondValue = my.Next(10);
            lbSecond.Text = m_SecondValue.ToString();
        }

        private void txtResult_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(char.IsDigit(e.KeyChar) == true) 

热点排行