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
Word Jumble program?
Started by JewFro297, Jan 19 2010 07:17 AM
3 replies to this topic
#1
Posted 19 January 2010 - 07:17 AM
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]
|
|
|
#2
Posted 19 January 2010 - 08:06 AM
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
Posted 19 January 2010 - 01:47 PM
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]
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]
#4
Posted 20 January 2010 - 10:29 AM


Sign In
Create Account


Back to top









