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";
}
}
I have been looking at this for the past 30 minutes and I know its something simple that I’m missing. When I execute the program and place the correct answer in TextBox1, Label3 still generates “InCorrect Answer.” I know this is remedial but what am I doing wrong?
Thanks
Try this out: