Function display problem

this is a Word Jumbling program and I can not get the hints to display. What am I doing wrong? Sorry about all the blank space.



#include <iostream>

#include <string>

#include <cstdlib>

#include <ctime>

using namespace std;

string randomWord();
string mixUp(const string& theWord);

void welcomePlayer(const string& jumble);

void play(const string& theWord);

string theHint;

int main()

{

srand(static_cast<unsigned int>(time(0)));
string word = randomWord();
string jumble = mixUp(word);
welcomePlayer(jumble);
play(word);



system("pause");
return 0;
}



string randomWord()

{
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?"},
{"persistent", "Keep at it."},
{"jumble", "It’s what the game is all about."}
};



srand(static_cast<unsigned int>(time(0)));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS[choice][WORD];// word to guess
string theHint = WORDS[choice][HINT];// hint for word
return theWord;

}



string mixUp(const string& theWord)

{

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;

}

return jumble;

}

void welcomePlayer(const string& jumble)

{

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 <<"\n\nThe jumble is: " << jumble<<"\n"<<endl;

}



void play(const string& theWord)

{

string guess;

string hint;

char again;

do

{

cout <<"\n\nYour guess: ";

cin >> guess;



while ((guess != theWord) && (guess != "quit"))
{
if(guess != theWord)
{
cout <<"Sorry, that's not it.";
}
cout <<"\n\nYour guess: ";
cin >> guess;
}
if (guess == theWord)
{
cout <<"\nThat's it! You guessed it!\n";
}
else if(guess == theHint)
{
cout<< theHint;
}

cout <<"\nThanks for playing.\n";
cout <<"\n Would you like to play again? y/n";
cin >> again;
}

while
((again == 'y' || again == 'Y') && (again != 'n' || again != 'N'));

}
Last edited on
Hi !
Code tags pls :D

I think this is the issue:
else if(guess == theHint)
You want the user to request a hint and not guess what the hint actually is.

Try else if(guess == "theHint")
Topic archived. No new replies allowed.