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

猜数器,该怎么解决

2013-03-27 
猜数器using Systemusing System.Collections.Genericusing System.ComponentModelusing System.Datau

猜数器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        Random ra = new Random();
        int Ra = 0;
        int cishu = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Ra = ra.Next(0,100);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string num = textBox1.Text.Trim();
            int shu = Int32.Parse(num);

            {
                if (shu > Ra)
                {
                    cishu++;
                    MessageBox.Show("你猜大了  " + "一共猜了" + cishu + "次");
                }
                else
                {
                    if (shu < Ra)
                    {
                        cishu++;
                        MessageBox.Show("你猜小了  " + "一共猜了" + cishu + "次");
                    }
                    else
                    {


                        cishu++;
                        MessageBox.Show("你猜对了   " + "一共猜了" + cishu + "次");
                    }
                }
            }
        }

    }
}


为什么无论输入什么数,运行结果都是
猜数器,该怎么解决
而且,请看图片中的Ra=ra.Next(0,100);这行中的逗号,别人是“,”,而我的是这样
我的随机数是在0到100之间产生的。
我看不出哪里有问题,求赐教
[解决办法]
先断点调试下吧,看看代码是怎么走的,输入不同的数字,监视全局变量的变化,以及代码执行进入了哪些循环。断点多看看,自己开发的程序,问题应该就找出来了。
[解决办法]
Ra = ra.Next(0,100);
把这个写到
       private void Form1_Load(object sender, EventArgs e)
        {

        }
里面

热点排行