Increase label7.text by 1 everytime the user makes a wrong guess
Everytime the user makes a wrong guess I want the label7.text to display that number. the way i have it it just stays at 1 and doesnt increment the next wrong guess.
private void button1_Click(object sender, EventArgs e)
{
int correct=0;
int incorrect=0;
RandomNumber(0,99);
button2.Enabled = true ;
button1.Enabled = false;
label3.Visible = true;
if (textBox1.Text == label1.Text)
{
l开发者_C百科abel3.Text = (string.Format("Winner"));
label6.Text = (++correct).ToString();
}
else if (textBox1.Text != label1.Text)
{
label7.Text = (++incorrect).ToString();
label3.Text = (string.Format("Sorry - You Lose, The number is {0}", label1.Text));
}
}
You need to remove the variables correct
and incorrect
from your button click's scope, and make them class-level variables instead. In your code, every time a user clicks the button, these variables are re-initialized to 0.
Like this:
private int correct = 0;
private int incorrect = 0;
private void button1_Click(object sender, EventArgs e)
{
RandomNumber(0,99);
button2.Enabled = true ;
button1.Enabled = false;
label3.Visible = true;
if (textBox1.Text == label1.Text)
{
label3.Text = (string.Format("Winner"));
label6.Text = (++correct).ToString();
}
else if (textBox1.Text != label1.Text)
{
label7.Text = (++incorrect).ToString();
label3.Text = (string.Format("Sorry - You Lose, The number is {0}", label1.Text));
}
}
精彩评论