| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 631 人关注过本帖
标题:四则运算中 赋值问题
只看楼主 加入收藏
f2831890
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:115
专家分:107
注 册:2009-11-25
结帖率:96.77%
收藏
已结贴  问题点数:20 回复次数:5 
四则运算中 赋值问题
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
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:5 
试了lz的代码 不能赋值  lz指的不能赋值是哪里啊?

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-12-04 09:57
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:5 
楼主应该比较清楚自己的代码应该做什么,那么在哪一步出现问题可以在哪里设个断点,看看变量的值,这样笼统的把代码都放在这里就比较乱,建议把出现问题的部分用彩色标记一下比较好!!
2010-12-04 17:42
f2831890
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:115
专家分:107
注 册:2009-11-25
收藏
得分:0 
在刚运行的时候 是能够给AB赋值  但问题答对后  AB的值就不在变化了  

QQ:412869766
2010-12-05 12:24
浩凡儿
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:101
专家分:394
注 册:2010-10-30
收藏
得分:5 
你也没有把用的那个form2的形式给出来也无法给你搞呀不过我感觉好像是没有引用那个numble1.Text与numble2.Text
你可以把它们的值赋给两个数吗!!
如string str1=numble1.Text;
  string str2=numble.Text;
int i1=Console.ToInt32(str1) ;   
int i2=Console.ToInt32(str2) ;                              
2010-12-05 20:29
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
快速回复:四则运算中 赋值问题
数据加载中...
 
   



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

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