标题:四则运算中 赋值问题
取消只看楼主
f2831890
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:115
专家分:107
注 册:2009-11-25
结帖率:96.77%
已结贴  问题点数:20 回复次数:2 
四则运算中 赋值问题
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 四则运算
{
    public partial class 四则运算 : Form
    {
        public 四则运算()
        {
            InitializeComponent();
        }
        
        
            int a ;
            int b ;
            int cj = 0;
            int sum = 0;
            Random myran = new Random();
            public void chuti()
            {
                number1.Text = a.ToString();
                number2.Text = b.ToString();
                sum = a + b;
            }

        private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "+";
            chuti();
        }
      
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            a = myran.Next(10);
            b = myran.Next(10);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            a = myran.Next(100);
            b = myran.Next(100);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            a = myran.Next(1000);
            b = myran.Next(1000);
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            a = myran.Next(10000);
            b = myran.Next(10000);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Text = "-";
           // chuti();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label2.Text = "*";
            //chuti();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label2.Text = "/";
            //chuti();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (textBox1.Text.ToString() == sum.ToString())
                {
                    cj = cj + 1;
                    zhoncj.Text ="总成绩:"+ cj.ToString();
                    textBox1.Text = "";
                    chuti();
                }
                else
                {
                    MessageBox.Show("答案是错误的!");
                    textBox1.Text = "";
                }

            }

        }

        private void 四则运算_Load(object sender, EventArgs e)
        {
            //chuti();
        }


    }
}
运行后 不能够赋值  这个是为什么????
搜索更多相关主题的帖子: 赋值 运算 
2010-12-03 18:41
f2831890
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:115
专家分:107
注 册:2009-11-25
得分:0 
在刚运行的时候 是能够给AB赋值  但问题答对后  AB的值就不在变化了  

QQ:412869766
2010-12-05 12:24
f2831890
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:115
专家分:107
注 册:2009-11-25
得分:0 
问题已经解决了   
贴上正确的代码  供参考
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 四则运算
{
    public partial class 四则运算 : Form
    {
        public 四则运算()
        {
            InitializeComponent();
        }
        
        
            int a=0 ;
            int b=0 ;
        int d=0;
            int cj = 0;
            Random myran = new Random();
            public void chuti()
            {
                int n = 0;
                if (radioButton1.Checked)
                {
                    n = 10;
                }
                if (radioButton2.Checked)
                {
                    n = 100;
                }
                if (radioButton3.Checked)
                {
                    n = 1000;
                }
                if (radioButton4.Checked)
                {
                    n = 10000;
                }
                    do
                {
                    a = myran.Next(n) + 1;
                    b = myran.Next(n) + 1;
                    d = a % b;
                }
                while (d != 0);
                {
                number1.Text = a.ToString();
                number2.Text = b.ToString();
                }
            }

        private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "+";
            chuti();
        }
      
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            a = myran.Next(10);
            b = myran.Next(10);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            do
            {
                a = myran.Next(90)+10;
                b = myran.Next(90)+10;
                d = a % b;
            }
            while (d != 0);
            {
                number1.Text = a.ToString();
                number2.Text = b.ToString();
            }
            chuti();
        }   

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            do
            {
                a = myran.Next(900)+100;
                b = myran.Next(900)+100;
                d = a % b;
            }
            while (d != 0);
            {
                number1.Text = a.ToString();
                number2.Text = b.ToString();
            }
            chuti();

        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            do
            {
                a = myran.Next(9000)+1000;
                b = myran.Next(9000)+1000;
                d = a % b;
            }
            while (d != 0);
            {
                number1.Text = a.ToString();
                number2.Text = b.ToString();
            }
            chuti();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Text = "-";
           chuti();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label2.Text = "*";
            chuti();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label2.Text = "/";
            chuti();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (int.Parse(textBox1.Text)== a+b)
                {
                    cj = cj + 1;
                    zhoncj.Text ="总成绩:"+ cj.ToString();
                    textBox1.Text = "";
                    chuti();
                }
                else if (int.Parse(textBox1.Text) == a - b)
                {
                    cj = cj + 1;
                    zhoncj.Text = "总成绩:" + cj.ToString();
                    textBox1.Text = "";
                    chuti();
                }
                else if (int.Parse(textBox1.Text) == a * b)
                {
                    cj = cj + 1;
                    zhoncj.Text = "总成绩:" + cj.ToString();
                    textBox1.Text = "";
                    chuti();
                }
                else if (int.Parse(textBox1.Text) == a / b)
                {
                    cj = cj + 1;
                    zhoncj.Text = "总成绩:" + cj.ToString();
                    textBox1.Text = "";
                    chuti();
                }
                else
                {
                    MessageBox.Show("答案是错误的!");
                    textBox1.Text = "";
                }

            }

        }

        private void 四则运算_Load(object sender, EventArgs e)
        {
            chuti();
        }


    }
}

QQ:412869766
2010-12-05 21:11



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




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

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