samedi 5 novembre 2016

Matching an entered String to a random String

I've been stuck on this for a while now and i cant seem to get it to work. I want my program to be able to select a random word from the "Words" array (array contents previously added by the user) and allow the user to then enter another word and see if it matches the randomly selected word selected by the program from the array. If the words match a message will be out put but if not a message will also be output but the system should indicate to the user if any letters that they had entered were in the random String. I know this is quite a bit but I've been stuck for ages haha, thanks! Here is part of the code i have been using, a bit simplified.

private void btnGuess_Click(object sender, EventArgs e) {

        string guess = txtGuess.Text;

        string[] words = new string[6];
        lstWords.Items.Add(txtEnterWord.Text);

        Random rand = new Random();

        for (int i = 0; i < words.Length; i++)
        {
            words[i] = rand.ToString();
        }
        if (String.Equals(guess, rand))
        {
            MessageBox.Show("Congratulations you have won! Your words are a match");
        }
        else
        {
            MessageBox.Show("Sorry but your words are not a match, try again");
        }
    }




Aucun commentaire:

Enregistrer un commentaire