// Word Jumble // The classic word jumble game where the player can ask for a hint #include #include #include #include using namespace std; int main() { enum fields {WORD, HINT, NUM_FIELDS}; const int NUM_WORDS = 5; const string ALLWORDS[NUM_WORDS][NUM_FIELDS] = { {"wall", "Do you feel you are banging your head against something?"}, {"glasses", "These might help you see the answer."}, {"creep", "Going slowly, is it?"}, {"persistent", "Keep at it."}, {"jumble", "What the game is all about."} }; srand(static_cast(time(0))); int choice = (rand() % NUM_WORDS); string theWord = ALLWORDS[choice][WORD]; // word to guess string theHint = ALLWORDS[choice][HINT]; // hint for word string jumble = theWord; // jumbled version of word 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\t\tWelcome to Word Jumble!\n\n"; cout << "Unscramble the letters to make a word.\n"; cout << "Enter \'hint\' for a hint.\n"; cout << "Enter \'quit\' to quit the game.\n\n"; cout << "The jumble is: " << jumble; string guess; cout << "\n\nYour guess: "; cin >> guess; while ((guess != theWord) && (guess != "quit")) { if (guess == "hint") { cout << theHint; } else { cout << "Nope, that\'s not it. Try again."; } cout <<"\n\nYour guess: "; cin >> guess; } if (guess == theWord) { cout << "\nThat\'s it! You guessed it!\n"; } cout << "\nThanks for playing.\n"; return 0; }