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

Below is the partial, non-commented, non-working code for a hangman game. Comple

ID: 3533230 • Letter: B

Question

Below is the partial, non-commented, non-working code for a hangman game. Complete the code. There is a list of words at the bottom. The program randomly picks a number and gets a word corresponding to that number, and uses that for the hangman game. Also the game outputs the actual picture of the hanggman. Thanks.

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

#include <string>

#include <fstream>

#include <iomanip>

#include <math.h>

#include <Ctime>

#include <iostream>


const int numwords = 34;


void DrawBody(int bodysize);


using namespace std;

const int WORDSIZE = 6;

const int BODYSIZE = 6;

int main(int argc, const char * argv[])

{



    ifstream wordlist;

    wordlist.open("wordlist.txt");

    if (!wordlist)

    {

cout << "couldn't find word list";

        return 1;

    }



    int whichword = rand()%(numwords)+1;

    string nextwordstring;

    string word;

    int dotlocation = nextwordstring.find(".");

    while(nextwordstring.substr(0,dotlocation) != "4")

    {wordlist >> nextwordstring;

    int dotlocation=nextwordstring.find(".");

        word = nextwordstring.substr(dotlocation+1);

    }

    cout << word;



//    string word = "tester";

    char wordA[WORDSIZE]= {'t','e','s','t','e','r'};

bool correctA[WORDSIZE] = {false, false, false, false, false, false};

    int bodyCount = 0;

    int numCorrect = 0;

    char userGuess;



    while ((bodyCount < BODYSIZE) && (numCorrect < WORDSIZE))

    {

        cout << "letter: ";

        cin >> userGuess;

        bool foundone = false;


        for(int i=0; i<WORDSIZE; i++)

        {

            if (userGuess == wordA[i])

            {

                correctA[i] = true;

                foundone = true;

                numCorrect++;

            }

        }



        if (! foundone)

            bodyCount++;



        cout << "bodycount = " << bodyCount << endl;

        DrawBody(bodyCount);



        for(int i=0; i<WORDSIZE; i++)

            if (correctA[i])

                cout << wordA[i];

            else

                cout << "_";



            cout << endl;

    }



    if (bodyCount >= BODYSIZE)

        cout << "you lose";

    else

        cout << "you win";



    return 0;

}


void DrawBody(int bodysize)

{

    cout << "|-----|"<<endl;

    switch (bodysize){

        case1:

            cout <<"|      O"<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            break;

        case2:

            cout <<"|      O"<<endl;

            cout <<"|      |"<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

        case3: cout <<"|"; break;

            cout <<"|      O"<<endl;

            cout <<"|     /|"<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            break;

        case4:

            cout <<"|      O"<<endl;

            cout <<"|      |"<<endl;

            cout <<"|     /|\"<<endl;

            cout <<"|      "<<endl;

            cout <<"|      "<<endl;

            break;

    }



text file of words:


1.abduce

2.abduct

3.abjure

4.ablest

5.abound

6.absurd

7.abused

8.abuser

9.acetyl

10.acquit

11.acuity

12.aculei

13.acumen

14.acuter

15.adieux

16.adjoin

17.adjure

18.adjust

19.advent

20.adverb

21.advert

22.advice

23.advise

24.afield

25.agnize

26.agonic

27.aguish

28.akimbo

29.albino

30.albite

31.alcove

32.alexin

33.algoid

34.alined


Explanation / Answer

HERE IS THE SIMPLE COMPACT AND BETTER CODE FOR HANGMAN. I am writting the functions

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