c#编写一个窗体出题的题,代码有误,希望帮看看
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Pro67
{
public partial class Form1 : Form
{
int x = 1, op1, op2, op, re1, re2, re3, re4, re5, right = 0, error = 0, score = 0;
string ss;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = ct(out re1);//re1...第一个式子的正确结果
label2.Text = ct(out re2);
label3.Text = ct(out re3);
}
public String tj(String s,int r) {
if (int.Parse(s) == r)
{
right += 1;
return "正确";
}
else {
error += 1;
return"错误";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void 简单ToolStripMenuItem_Click(object sender, EventArgs e)
{
x = 1;
}
private void 中等ToolStripMenuItem_Click(object sender, EventArgs e)
{
x = 2;
}
private void 极难ToolStripMenuItem_Click(object sender, EventArgs e)
{
x = 3;
}
public String ct(out int re) {
Random rad = new Random();
op = rad.Next(0, 3) + 1;
if(x==1){
op1 = rad.Next(0,9) + 1;
op2 = rad.Next(0, 9) + 1;
}
else if (x == 2)
{
Random rnd = new Random();
op1 = rnd.Next(9, 19) + 1;
op2 = rnd.Next(9, 19) + 1;
op = rnd.Next(0, 3) + 1; //[1,4]
}
else {
Random rnd = new Random();
op1 = rnd.Next(19, 29) + 1;
op2 = rnd.Next(19, 29) + 1;
op = rnd.Next(0, 3) + 1;
}
switch (op)
{
case 1: re = op1 + op2;
ss = op1.ToString() + "+" + op2.ToString() + "="; break;
case 2: re = op1 - op2;
ss = op1.ToString() + "-" + op2.ToString() + "="; break;
case 3: re = op1 * op2;
ss = op1.ToString() + "*" + op2.ToString() + "="; break;
case 4: re = op1 / op2;
ss = op1.ToString() + "/" + op2.ToString() + "="; break;
}
re = 1;
return ss;
}
private void button2_Click(object sender, EventArgs e)
{
label4.Text = tj(textBox1.Text,re1);
label5.Text = tj(textBox2.Text,re2);
label6.Text = tj(textBox3.Text,re3);
richTextBox1.Text += DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日 ,做的题是:"
+ label1.Text + textBox1.Text + label4.Text + "," + label2.Text + textBox2.Text + label5.Text + "," + label3.Text + textBox3.Text + label6.Text + ",成绩" + score;
}
}
}
出的题都一样,而且给出正确答案,还是说是错的,怎么回事?