Closed Thread
Results 1 to 6 of 6

Thread: Help needed with word scramble program!

  1. #1
    proggcat is offline Newbie
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Help needed with word scramble program!

    Sorry to bother any of you but I need help regarding a word scramble program I am working on for class.

    Instructions stated that I am supposed to generate a random number to use as the index of the word in an array, then retrieve the word from the array, using the first random number as an index. Store the word in another string variable. And then to generate a second random number to store the index of a character to be moved.

    I am supposed to use a for statement to iterate through a word 20 times. Each time the loop executes, pass the second random number created earlier to the string indexer. Append the character returned by the idexer to the end of the string, and remove it from its original position.

    Next, generate a new random number to move a different character during the next iteration of the loop.

    This is what I have done so far.
    Code:
                    for (int count = 0; count < 20; count++)
                    {
                        string strAnagram;
                        string strAnagram1;
                        string strAnagram2;
    
                        strAnagram1 = strWord[intRandom];
                        strAnagram2 = strWord[intRandom];
    
                        strAnagram1 = strWord[intRandom].Substring(1, 1);
                        strAnagram2 = strWord[intRandom].Remove(1, 1);
    
                        strAnagram = strAnagram2.Insert(7, (strWord[intRandom].Substring(1, 1)));
    
                        lblAnagram.Text = strAnagram;
    
                    }
    It works but not in the way the instruction stated. I would appreciate all the help I can get Thank you very much!
    Last edited by WingedPanther; 08-05-2009 at 01:01 PM. Reason: add code tags (the # button)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    proggcat is offline Newbie
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Re: Help needed with word scramble program!

    and the count thing doesnt work, unfortunately it only removes the 2nd character and add it to the end of the word

  4. #3
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Help needed with word scramble program!

    Can you give an example of the desired input/output and what you're getting? You may want to include a little more code, as many of your variables and defined/initialized in the code block listed.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    proggcat is offline Newbie
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Re: Help needed with word scramble program!

    hey thanks for replying this is my entire code.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace anagram_
    {
        public partial class Form1 : Form
        {
            int intRandom = 0;
            int count = 0;
            string[] strWord = { "engineer", "toenails", "penguins", "asterisk", "appetite", "backstab", "junkyard", "werewolf", "princess", "trespass" };
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {            
                Random r = new Random();
                intRandom = r.Next(0, 10);
    
                for (int i = 0; i < 20; i++)
                {
                    string strAnagram;
                    string strAnagram1;
                    string strAnagram2;
                    
                    strAnagram1 = strWord[intRandom];
                    strAnagram2 = strWord[intRandom];
    
                    strAnagram1 = strWord[intRandom].Substring(1, 1);
                    strAnagram2 = strWord[intRandom].Remove(1, 1);
    
                    strAnagram = strAnagram2.Insert(7, (strWord[intRandom].Substring(1,1)));
    
                    lblAnagram.Text = strAnagram;
    
                }
                
                txtGuess.Focus();
            }
    
            private void btnSubmit_Click(object sender, EventArgs e)
            {
                string strGuess;
                strGuess = txtGuess.Text;
                
                if (strGuess.ToLower() == strWord[intRandom])
                {
                    lblResult.Text = "You are CORRECT!";
    
                    Random r = new Random();
                    intRandom = r.Next(0, 10);
    
                    for (int count = 0; count < 20; count++)
                    {
                        string strAnagram;
                        string strAnagram1;
                        string strAnagram2;
    
                        strAnagram1 = strWord[intRandom];
                        strAnagram2 = strWord[intRandom];
    
                        strAnagram1 = strWord[intRandom].Substring(1, 1);
                        strAnagram2 = strWord[intRandom].Remove(1, 1);
    
                        strAnagram = strAnagram2.Insert(7, (strWord[intRandom].Substring(1, 1)));
    
                        lblAnagram.Text = strAnagram;
    
                    }
    
                    txtGuess.Clear();
                }
                else
                {
                    lblResult.Text = "Wrong! Please try again!";
                }
    
                txtGuess.Focus();
            }
        }
    }
    This is done in microsoft visual studio 2005. When the user opens the word scramble program, they're presented with 2 labels, a textbox and a button. The top is the label which contains the 'scrambled' word, the textbox is the place the player is supposed to input his guess, the bottom is the label where the player will know if they guessed the word correctly and the button is submit.

  6. #5
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Help needed with word scramble program!

    So basically they get the see the "scrambled" word, and they have to guess what the real word is?

    You are having a bit of trouble generating the scrambled word right? Well you could use the same way of doing it, make a bunch of scrambled words and pick, etc etc etc...

  7. #6
    gaylo565's Avatar
    gaylo565 is offline Programming Professional
    Join Date
    May 2007
    Location
    flagstaff, az
    Posts
    268
    Rep Power
    21

    Re: Help needed with word scramble program!

    There seemed to be quite a few issues with the code you had. I fixed it up a bit for ya You should probably learn how to turn instructions into usable code on your own in order to pass the class or just become a more proficient programmer. I dont usually help with homework but I am because you had most of what you needed there, it just needed some tweaking.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WordScramble
    {
            public partial class Form1 : Form
            {
                Random r = new Random();
                Random r2 = new Random();
                private string strStoreWord;
                int intRandom = 0;
                string[] strWord = { "engineer", "toenails", "penguins", "asterisk", "appetite", "backstab", "junkyard", "werewolf", "princess", "trespass" };
    
                public Form1()
                {
                    InitializeComponent();
                }
    
                private void wordScramble()
                {
                    string strAnagram = null;
                    intRandom = r.Next(10);
                    strAnagram = strWord[intRandom];
                    strStoreWord = strAnagram;
                    for (int i = 0; i < 20;i++ )
                    {
                        string strAnagram2;
    
                        int intRandom2 = r2.Next(strAnagram.Length);
                        strAnagram2 = strAnagram.Substring(intRandom2, 1);
    
                        strAnagram = strAnagram.Remove(intRandom2, 1);
    
                        strAnagram = strAnagram.Insert(strAnagram.Length, strAnagram2);
                    }
                    lblAnagram.Text = strAnagram;
    
                    txtGuess.Focus();
                }
    
                private void Form1_Load_1(object sender, EventArgs e)
                {
                    wordScramble();
                }
    
                private void btnSubmit_Click_1(object sender, EventArgs e)
                {
                    string strGuess;
                    strGuess = txtGuess.Text.ToString();
    
                    if (strGuess.ToLower() == strStoreWord)
                    {
                        lblResult.Text = "You are CORRECT!";
    
                        txtGuess.Clear();
                        wordScramble();
                    }
                    else
                    {
                        lblResult.Text = "Wrong! Please try again!";
                        txtGuess.Clear();
                    }
    
                    txtGuess.Focus();
                }
            }
    
        }
    You could also use to add a keyup event handler so that when the user is done typing they just have to hit enter to click the submit button...just a thought. Hope this helps you out!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Word Scrambler Program Help
    By karch1992 in forum Java Help
    Replies: 4
    Last Post: 03-29-2011, 12:45 PM
  2. Word count program noobie help
    By code_prowannabe in forum C and C++
    Replies: 2
    Last Post: 11-21-2010, 06:47 PM
  3. Word Jumble program?
    By JewFro297 in forum C and C++
    Replies: 3
    Last Post: 01-20-2010, 10:29 AM
  4. Need help w/ word count program (ASAP)
    By siren in forum C and C++
    Replies: 3
    Last Post: 09-11-2009, 05:17 AM
  5. need help with word count C++ program
    By waynejr25 in forum C and C++
    Replies: 2
    Last Post: 11-02-2007, 02:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts