I’m doing a hangman game, and just started to created the random word that will generate new word that users have to guess however sometimes the random code will generate the same word that was used previously. My question is… is there a symbol or code that will say if random number is not equal to… do this block of code.
Here’s my code…
private void button1_Click(object sender, EventArgs e)
{
Random rW = new Random();
foreach (TextBox textBox in addTextBox())
{
textBox.Visible = false;
}
RW = rW.Next(1, 4);
if (RW == 1) //Cat
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
}
else if (RW == 2) //Elephant
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
textBox8.Visible = true;
}
else if (RW == 3) //Giraffe
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
}
else if (RW == 4) //Monkey
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
}
else
{
}
}
You should use
!=which is an equality operator.