mardi 13 janvier 2015

C# - textbox.text wont compare to "stringed" integer value

For a simple little math quiz i'm generating two numbers, adding them up in an int called(questionAnswer)and than comparing the user input in the textbox to questionAnswer. But for some reason (even if i type in the correct answer) it does nothing. Is my way of comparing textbox.text to an integer invalid or is there some sort of logical error?



public void inputCheck()
{
Random level1random = new Random();
int firstValue = level1random.Next(0, 15);
int secondValue = level1random.Next(0, 15);
int questionAnswer = firstValue + secondValue;

leftImageBox.Content = firstValue;
rightImageBox.Content = secondValue;

if(answerBox.Text == questionAnswer.ToString())
{
MessageBox.Show("hoeray!");
answerBox.Clear();
return;
}
}


code for the submit button



private void submit_MouseUp(object sender, MouseButtonEventArgs e)
{
inputCheck();
}

Aucun commentaire:

Enregistrer un commentaire