Heading Here
Hi there, I have been googling and been on youtube to find a solution. Now I need your help. I have a little problem that is bugging
public partial class Form1 : Form
{
public Form1(){
{
InitializeComponent();
}
//declare the variables you will use in the randomizer above the code block
private char[] letters = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
private char secretLetter = ' '; //I am not sure if this is correct????
private char myGuess;
private string GameResult;
private void btnRandom_Click(object sender, EventArgs e)
{
Random rand = new Random();
//the random number must have a range of numbers to choose from.
int myRandomNumber = rand.Next(0, letters.Length - 1);
secretLetter = letters[myRandomNumber];
}
private void btnCheck_Click(object sender, EventArgs e)
{
//converting a string to a char
myGuess = char.Parse(txtMessage.Text);
if (char.IsWhiteSpace(myGuess))
{
MessageBox.Show("Please choose a letter between a and g!");
}
else
{
if (secretLetter == myGuess)
{
MessageBox.Show("Congratulations, you guessed correctly");
}
else
{
GameResult = string.Format("Sorry your guess of {0} is incorrect, the secretLetter is {1}",
myGuess, secretLetter);
//secretLetter **s not recognized by my code******************
}
// MessageBox.Show(GameResult);
}
}
}
}
me. You need to first create a form with a Randomize button, a textbox and a Check button.
The question: when the user clicks on the randomize button, load a char arry with the letters a,b,c,d,e,f,g. The computer must then choose a random character from this array. Do not show the user the character yet. The user must enter their guess of what they think the character is into the textbox. Once the check button is checked, show the user a message stating whether the guess was correct or not.*****This is my code:*****************************
namespace Unit_3_Practical_Pretest_1