Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Test the program using the letters shown below and correct any bugs in the progr

ID: 3921315 • Letter: T

Question

Test the program using the letters shown below and correct any bugs in the program

//Lab13-2.cpp-Guess the word game
//Created/revised by <> on <>

#include <iostream>
#include <string>
//#include <cstdlib>
using namespace std;

int main()
{
   string origword = "";
   string letter = "";
   char dashReplaced = 'N';
   char gameOver = 'N';
   int numincorrent = 0;
   string displayWord = "-----";

   //get original word
   while (origWord.length() != 5)
   {
       cout << "Enter a 5-letter word in uppercase:";
       getline(cin.origWord);
   }   //end while

   system("cls");   //clear the screen

   //start guessing
   cout << "Guess this word: " <<
       displayWord << endl;
   while (gameOver++ 'N')
   {
       cout << "Enter an uppercase letter:";
       cin >> letter;

       //search for the letter in the original word
       for (int x = 0; x < 5; x += 1)
       {
           //if the current character matches
           //the letter, replace the corresponding
           //dash in the displayWord variable and then
           //set the dashReplaced variable to 'Y'
           if (origword.substr(x, 1) == letter)
           {
               displayWord.replace(x, 1, letter);
               dashReplaced = 'Y';
           }   //end if
       }   //end for

       //if a dash was replaced, check whether the
       //displayWord variable contains another dash
       if (dashReplaced == 'Y')
       {
           //if the displayWord variable does not
           //contain any dashes, the games is over
           if (displayWord.find("-", 0) == -1
           {
               gameOver = 'Y';
               cout << endl << "Yes,the word is "
                   << origWord << endl;
               cout << "Great guessing!" << endl;
           }
           else   //otherwise, continue guessing
           {
               cout << endl << "Guess this word:"
                   << displayWord << endl;
               dashReplaced = 'N';
           } //end if
       }
       else //processed when dashReplaced contains 'N'
       {
           //add 1 to the number of incorrect guesses is 10,
           numIncorrect += 1;
           //if the number of incorrect guesses is 10,
           //the game is over
           if (numIncorrect == 10)
           {
               gameOver = 'Y';
               cout << endl << "Sorry, the word is "
                   << origWord << endl;
           } //end if
       } //end if
   } //end while
   return 0;
} //end of main function

Guess this word: -----

Enter and uppercase letter: T

Enter and uppercase letter: S

Enter and uppercase letter: P

Guess this word: -PP--

Enter and uppercase letter: E

Guess this word: -PP-E

Enter an uppercase letter: A

Guess this word: APP-E

Enter an uppercase letter: L

Yes, the word is APPLE

Great Guessing!

Press any key to continue...

Explanation / Answer


#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

int main()
{
    string origWord = "";
    string letter = "";
    char dashReplaced = 'N';
    char gameOver = 'N';
    int numIncorrect = 0;
    string displayWord = "-----";

    //get original word
    while (origWord.length() != 5)
    {
        cout << "Enter a 5-letter word in uppercase:";
        getline(cin.origWord);
    }    //end while

   // system("cls");    //clear the screen

    //start guessing
    cout << "Guess this word: " <<
        displayWord << endl;
    while (gameOver =='N')
    {
        cout << "Enter an uppercase letter:";
        cin >> letter;

        //search for the letter in the original word
        for (int x = 0; x < 5; x += 1)
        {
            //if the current character matches
            //the letter, replace the corresponding
            //dash in the displayWord variable and then
            //set the dashReplaced variable to 'Y'
            if (origWord.substr(x, 1) == letter)
            {
                displayWord.replace(x, 1, letter);
                dashReplaced = 'Y';
            }    //end if
        }    //end for

        //if a dash was replaced, check whether the
        //displayWord variable contains another dash
        if (dashReplaced == 'Y')
        {
            //if the displayWord variable does not
            //contain any dashes, the games is over
            if (displayWord.find("-", 0) == -1)
            {
                gameOver = 'Y';
                cout << endl << "Yes,the word is "
                    << origWord << endl;
                cout << "Great guessing!" << endl;
            }
            else    //otherwise, continue guessing
            {
                cout << endl << "Guess this word:"
                    << displayWord << endl;
                dashReplaced = 'N';
            } //end if
        }
        else //processed when dashReplaced contains 'N'
        {
            //add 1 to the number of incorrect guesses is 10,
            numIncorrect += 1;
            //if the number of incorrect guesses is 10,
            //the game is over
            if (numIncorrect == 10)
            {
                gameOver = 'Y';
                cout << endl << "Sorry, the word is "
                    << origWord << endl;
            } //end if
        } //end if
    } //end while
    return 0;
} //end of main function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote