Jump to content

Word Jumble program?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
In my class I have to make a program that follows this pseudocode:
create a list of possible secret words.
Pick a secret word from the list of possibilities.
create a jumbled version of the secret word.
Welcome the player to the game.
Display the jumbled word.
have the player try to guess the word yata yata.

Any Ideas how I could go about doing this? Ive tried like three different ways
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Is this for C or C++? That has a lot to do with how you'd go about doing this, in C you'd want to create a data structure that held all of the possible secret words, and in C++ you'd want to create a SecretWordList object and then query it for random words. Anyway, assuming this is C, I'd first decide how you're going to determine what the secret words are. Will they be hard coded, or will you load them from a data file? After that, getting the computer to choose a random word isn't terribly difficult:
const char* get_random_word(struct wordList* list)
{
    return list->words[rand() % list->size];
}
To jumble that word also shouldn't be too hard, you'd want to do something like this:
char* jumble_word(char* word)
{
    int word_length = strlen(word);
    /* We'll shuffle it by looping through each character and picking another
       one from the string then swapping them. */
    for (int iii = 0; iii < word_length - 1; ++iii)
    {
        int rval = rand() % (word_length - iii);
        char temp = word[iii];
        word[iii] = word[iii + rval];
        word[iii + rval] = temp;
    }
    return word;
}
After that, it's mostly just printf's and user input as normal. So yeah, C or C++?
Wow I changed my sig!

#3
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
C++, that looks helpful though. I havn't gotten to OOP yet though, but i can learn it if thats the best way to get this done. well I sorta learned some of it over the summer, but I completely forgot it.
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#4
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
solved, thanks for the help
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]