public partial class Addition : System.Web.UI.UserControl
{
int Add1;
int Add2;
int answer;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
//Generates ramdom numbers for addition problem
Random oRand = new Random();
Add1 = oRand.Next(30);
Add2 = oRand.Next(30);
Label1.Text = Add1.ToString();
Label2.Text = Add2.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Validates users answer
answer = Convert.ToInt32(TextBox1.Text);
if (Add1 + Add2 != answer)
Label3.Text = "InCorrect Answer";
else
Label3.Text = "Correct Answer";
}
}
在过去的 30 分钟里,我一直在看这个,我知道我错过了一些简单的东西。当我执行程序并将正确答案放在 TextBox1 中时,Label3 仍然会生成“InCorrect Answer”。我知道这是补救措施,但我做错了什么?
谢谢