// Guess My Word #include <iostream> #include <cstdlib> #include <ctime> #include <string> using namespace std; int main () { enum fields {WORD,HINT,NUM_FIELDS}; const int NUM_WORDS = 5; const string WORDS[NUM_WORDS][NUM_FIELDS] = { {"wall","Do you fell you are banging your head againest something?"}, {"glasses","These might help you see the answer."}, {"labored","Going slowly,is it?"}, {"persistent","Keep at it"}, {"jumble","It's what the game si all about."} }; srand(time(0)); int choice = (rand()%NUM_WORDS); string theWord = WORDS[choice][WORD]; string theHint = WORDS[choice][HINT]; 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/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 << "/nyou guess is: "; cin>>guess; while((guess != theWord)&&(guess!="quit")) { if (guess=="hint") cout<<theHint; else cout<<"Sorry,that is not it!/n"; cout << "/nyou guess is: "; cin>>guess; } if (guess == theWord) cout << "That's it , you guess it !/n"; cout <<"/nThanks for you playing./n"; return 0 ; }