自动出题并判定结果

想在C站找到组织。
第一个练习笔记!

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoPanDing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a;
int b;
string c;
int result;
Random rnd = new Random();
private void btnNew_Click(object sender, EventArgs e)
{
a = rnd.Next(0, 9);
b = rnd.Next(1, 9);//考虑分母不为零;
int d = rnd.Next(4);//定义label2出现的情况;
switch (d)
{
case 0: c = “+”; result = a + b;
break;
case 1: c = “-“; result = a - b;
break;
case 2: c = ““; result = a b;
break;
case 3: c = “%”; result = a % b;

                    break;
            }
                this.label1.Text = a.ToString();
                this.label3.Text = b.ToString();
                this.label2.Text = c;
                this.txtJieGuo.Text = "";
    }

    private void btnpanDing_Click(object sender, EventArgs e)
    {
                string str = this.txtJieGuo.Text;
                double M = double.Parse(str);//把字符串强行转换double类型;
                //this.listBox1 = this.a * this.b;
                //this.txtJieGuo.Text = result.ToString();
                //this.listBox1.Text = "正确";
                //this.txtJieGuo.Text != result.ToString();
                string disp = "";
                if (M == result)
                    disp = "正确";
                else
                    disp = "错误";
                listBox1.Items.Add(disp); 
    }
}

}


阅读更多
文章标签: c#
个人分类: c#
下一篇C#之继承
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭