*   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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education