3个回答
展开全部
代码你在修改下就可以了,添加上算正确率的逻辑,就OK了
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int label1str = 0;
double Result = 0;
Random rd = new Random();
private int IntegerY()
{
Random rd = new Random();
int A = rd.Next(1,4);
return A;
}
private void ShowQuestion()
{
double x = Convert.ToDouble(rd.Next(0, 10000));
double y = Convert.ToDouble(rd.Next(0, 10000));
switch (IntegerY())
{
case 1:
richTextBox1.Text = x + " + " + y + " = ( )";
Result = x + y;
break;
case 2:
richTextBox1.Text = x + " - " + y + " = ( )";
Result = x - y;
break;
case 3:
richTextBox1.Text = x + " * " + y + " = ( )";
Result = x * y;
break;
case 4:
if (y != 0)
{
richTextBox1.Text = x + " / " + y + " = ( )";
Result = x / y;
}
break;
}
}
private Timer timer1 = new Timer();
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
ShowQuestion();
}
void timer1_Tick(object sender, EventArgs e)
{
label1.Text = (label1str++).ToString();
if (Convert.ToInt32(label1.Text) > 59)
{
label1str = 0;
ShowQuestion();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
double AnswerResult = Convert.ToDouble(textBox1.Text);
if (AnswerResult == Result)
{
label2.Text = "回答正确";
label2.ForeColor = Color.Green;
ShowQuestion();
label1str = 0;
}
else
{
label2.Text = "回答错误,正确答案为:" + Result;
label2.ForeColor = Color.Red;
ShowQuestion();
label1str = 0;
}
}
catch
{
label2.Text = "请输入合法的数字!!!";
label2.ForeColor = Color.Red;
}
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int label1str = 0;
double Result = 0;
Random rd = new Random();
private int IntegerY()
{
Random rd = new Random();
int A = rd.Next(1,4);
return A;
}
private void ShowQuestion()
{
double x = Convert.ToDouble(rd.Next(0, 10000));
double y = Convert.ToDouble(rd.Next(0, 10000));
switch (IntegerY())
{
case 1:
richTextBox1.Text = x + " + " + y + " = ( )";
Result = x + y;
break;
case 2:
richTextBox1.Text = x + " - " + y + " = ( )";
Result = x - y;
break;
case 3:
richTextBox1.Text = x + " * " + y + " = ( )";
Result = x * y;
break;
case 4:
if (y != 0)
{
richTextBox1.Text = x + " / " + y + " = ( )";
Result = x / y;
}
break;
}
}
private Timer timer1 = new Timer();
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
ShowQuestion();
}
void timer1_Tick(object sender, EventArgs e)
{
label1.Text = (label1str++).ToString();
if (Convert.ToInt32(label1.Text) > 59)
{
label1str = 0;
ShowQuestion();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
double AnswerResult = Convert.ToDouble(textBox1.Text);
if (AnswerResult == Result)
{
label2.Text = "回答正确";
label2.ForeColor = Color.Green;
ShowQuestion();
label1str = 0;
}
else
{
label2.Text = "回答错误,正确答案为:" + Result;
label2.ForeColor = Color.Red;
ShowQuestion();
label1str = 0;
}
}
catch
{
label2.Text = "请输入合法的数字!!!";
label2.ForeColor = Color.Red;
}
}
}
展开全部
您是老师吗。。。
窗体程序,加一个Timer,5个label和一个textbox,1个button
Timer的事件属性设成1000
Form_Load事件
LabelTime.Text = "60";
Timer.Start();
newWork();
-------------------
int correct = 0;
int count = 0;
void newWork(){
Random rd = new Random();
Label1.Text = rd.Next(1,100);
Label3.Text = rd.Next(1,100);
string[] fuhao = new string[]{"+","-","*","/"};
Label2.Text = fuhao[rd.Next(1,5)];
}
int getresult()
{
float result = 0;
int a = int.Parse(Label1.Text);
int b = int.Parse(Label2.Text);
switch(Label2.Text)
{
case "+":
result = a+b;
break;
case "-":
result = a-b;
break;
case "*":
result = a*b;
break;
case "/":
result = a/b
break;
}
}
-----------------------
button_Click事件
count++;
int result = int.Parse(textBox1.Text);
if(result == getresult())
{
correct ++;
}
newWork();
Timer_Tick事件
int second = int.Parse(LabelTime.Text);
if(second != 0)
{
second--;
}
else
{
textBox1.Text.Enable = false;
MessageBox.Show("共答"+count.ToString()+"题,答对"+correct.ToString()+"题,正确率"+(correct/count).ToString()+"");
Timer.Stop();
}
窗体程序,加一个Timer,5个label和一个textbox,1个button
Timer的事件属性设成1000
Form_Load事件
LabelTime.Text = "60";
Timer.Start();
newWork();
-------------------
int correct = 0;
int count = 0;
void newWork(){
Random rd = new Random();
Label1.Text = rd.Next(1,100);
Label3.Text = rd.Next(1,100);
string[] fuhao = new string[]{"+","-","*","/"};
Label2.Text = fuhao[rd.Next(1,5)];
}
int getresult()
{
float result = 0;
int a = int.Parse(Label1.Text);
int b = int.Parse(Label2.Text);
switch(Label2.Text)
{
case "+":
result = a+b;
break;
case "-":
result = a-b;
break;
case "*":
result = a*b;
break;
case "/":
result = a/b
break;
}
}
-----------------------
button_Click事件
count++;
int result = int.Parse(textBox1.Text);
if(result == getresult())
{
correct ++;
}
newWork();
Timer_Tick事件
int second = int.Parse(LabelTime.Text);
if(second != 0)
{
second--;
}
else
{
textBox1.Text.Enable = false;
MessageBox.Show("共答"+count.ToString()+"题,答对"+correct.ToString()+"题,正确率"+(correct/count).ToString()+"");
Timer.Stop();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询