*   This is the code for the Word Jumble game from Chapter 3.   Improve the Word Jumble game by adding a scoring system. Make the point valuefor a word based on its length. Deduct points if   the player asks for a hint. */ // 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 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(time(0)));     int choice = (rand() % NUM_WORDS);     string theWord = WORDS[choice][WORD]; //word to guess     string theHint = WORDS[choice][HINT]; //hint for the word     string jumble = theWord; //jumbled version of the world     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 << "Sorry, that's not it.";         }                  cout << "\n\nYour guess: ";         cin >> guess;     }     if (guess == theWord)     {         cout << "\nThat's it! You guessed it!\n";     }     cout << "\nThanks for playing.\n";     return 0; }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question
100%

/*
  This is the code for the Word Jumble game from Chapter 3.

  Improve the Word Jumble game by adding a scoring system. Make the point valuefor a word based on its length. Deduct points if   the player asks for a hint.

*/

// 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] = 
    {
        {"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 the word

    string jumble = theWord; //jumbled version of the world
    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 << "Sorry, that's not it.";
        }
        
        cout << "\n\nYour guess: ";
        cin >> guess;
    }

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

    cout << "\nThanks for playing.\n";

    return 0;
}

Expert Solution
Changes made to the original code
  1. Added an integer variable points to keep track of the player's score.
  2. Initialized points to the length of the word to be guessed.
  3. Added a boolean flag hintTaken to keep track of whether the player has taken a hint or not.
  4. Added points-- after each incorrect guess or hint taken to deduct a point from the player's score.
  5. Added an if statement to check if the player guessed the word without taking a hint, and added two bonus points to the player's score if this is the case.
  6. Displayed the player
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT