Math Game Help
hi, i am creating a math game for a class i'm in. i am creating a math game but i am having trouble trying to figure out how to check to see if the answer that was being input in correct or not that shows up in the text box. thanks in advance for the help. i am also posting the code i have written so far.
VulpesPosted Mar 10, 2011, 4:02 PM
Suthish NairPosted Mar 12, 2011, 1:02 PM
Guest UserPosted Mar 10, 2011, 10:41 PM
snounPosted Mar 10, 2011, 6:09 PM
FroglegPosted Mar 10, 2011, 5:51 PM
int score = 0;
at the top of your class
if answer is correct add 10 to score
score= score + 10;//adds ten to score
lblScore.Text = ("Score = " + Convert.ToString(score));
snounPosted Mar 10, 2011, 5:34 PM
FroglegPosted Mar 10, 2011, 4:54 PM
VulpesPosted Mar 10, 2011, 4:18 PM
I've also noticed a small mistake in btnSub_Click which will prevent it from working correctly:
snounPosted Mar 10, 2011, 4:09 PM
Guest UserPosted Mar 10, 2011, 4:06 PM
private void btnSubmit_Click(object sender, EventArgs e)
{
if (txtNum1.Text != "" && txtNum2.Text != "" && txtBoxAns.Text != "")
{
int correctAnswer = 0;
int userAnswer = Int32.Parse(txtBoxAns.Text);
int num1 = Int32.Parse(txtNum1.Text);
int num2 = Int32.Parse(txtNum2.Text);
if (lblSign.Text == @"+")
{
correctAnswer = num1 + num2;
}
if (correctAnswer == userAnswer)
{
MessageBox.Show(@"Correct!");
}
else
{
MessageBox.Show(@"Incorrect...");
}
}
else
{
MessageBox.Show(@"Please select an operator and enter your answer");
}
}