Hey, I got a new problem guys.
I have a word jumbler, and you have get the word, anyways look at the code and you'll understand.. My problem is that:
1. It doesn't allow you to do each of the words, it only lets you do the first word. I set up a count variable, but it doesn't work for me for some reason, I can't seem to understand why.![]()
2. I'd like to make sure it doesn't repeat the same words twice.
3. And I'd like to find any way to minimize errors (in a way I could understand)
If you could help me with this code, I'd appreciate it.Code://Word Jumble #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <limits> using namespace std; int main() { int count; int game; while ((count < 5) || (game != 1)) { enum fields {WORD, HINT, NUM_FIELDS}; const int NUM_WORDS = 5; const string WORDS[NUM_WORDS][NUM_FIELDS]= { {"wall", "Do you feel you're banging your head against something?"}, {"glasses", "These might help you see the answer"}, {"labored", "Going slowly is it?"}, {"persistant", "Keep at it."}, {"jumble","It's what the game is all about."} }; srand(time(0)); int choice = (rand() % NUM_WORDS); string theWord = WORDS[choice][WORD]; //Word to guess string theHint = WORDS[choice][HINT]; // Hint //NOT SURE?? MAYBE LATER IGNORE FOR NOW // int wall, glasses, labored, persistant, jumble; // if (WORDS[0][0] == WORD) // wall = 1; // if (WORDS[1][0] == WORD) // glasses = 1; // if (WORDS[2][0] == WORD) // // if (WORDS[3][0] == WORD) // if (WORDS[4][0] == WORD) string jumble = theWord; int length = jumble.size(); for (int i = 0; i < length; ++i) { int index1 = (rand() %length); int index2 = (rand() %length); char temp = jumble[index1]; jumble[index1] = jumble[index2]; jumble[index2] = temp; } cout << "\t\tWelcome to Word Jumble"; cout << "\nUnscramble the letters to make a word.\n"; cout << "Enter 'hint' for a hint.\n\n"; cout << "Enter 'quit' to quit the game.\n\n"; cout << "The jumble is: " <<jumble; string guess; cout<<"\n\nYour guess: "; cin >> guess; cout << "\n\nYour guess is: " << guess; while ((guess != theWord) & (guess != "quit")) { if (guess == "hint") { cout << "\n\n" << theHint; } else cout << "\nSorry that's not it."; cout << "\n\n Your guess: "; cin >> guess; if (guess == theWord) { cout << "\nThat's it! You guessed it!\n\n"; cout << "\nThanks for playing!.\n"; } } char exit; cout << "\nType 0 to exit, type anything else to play again: "; cin >> exit; if ((exit == 0) || (count = 5)) { if (count == 5) { cout << "\nYou have played already unscrambled 5 words!\n"; cout << "Please make another payment for another game\n"; cout << "\nPress enter to exit"; cin.ignore(numeric_limits<streamsize>::max(), '\n'); cin.get(); return 0; } else { cout << "\nPress enter to exit"; game = 1; } } else { count = count++; }; }; return 0; }
Thanks,
-Vic



LinkBack URL
About LinkBacks



