// Word Jumble
// The classic word jumble game where the player can ask for a hint

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
    enum fields {WORD, HINT, NUM_FIELDS};
    const int NUM_WORDS = 5;
    const string WORDS[NUM_WORDS][NUM_FIELDS] =
        {"abbott", "part of colton's name"},
        {"glasses", "These might help you see the answer."},
        {"labored", "Going slowly, is it?"},
        {"persistent", "Keep at it."},
        {"mississippi", "It's a state."}

	int choice = (rand() % NUM_WORDS);
    string theWord = WORDS[choice][WORD];  // word to guess
    string theHint = WORDS[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;
            cout << "Sorry, that's not it.";

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

    if (guess == theWord)
        cout << "\nThat's it!  You guessed it!\n";

    return 0;

Edited by WaltP: Added CODE Tags for the third time

8 Years
Discussion Span
Last Post by Grn Xtrm

Please use code tags.
I'm not sure what you mean by repeat the program, but it looks like you are since your using a while loop.


Just add a while loop at the beginning of the code and close it at the end. This is a simple way to allow repetition of a program.

char again='y';
    while(again == 'y')
    {   //execute the program

cout<<"Would you like to run again?"<<endl;
        }//close while loop
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.