Finish the following hangman C++ program and make it run well as well as comment the program through to help me understand the code perfectly without unclear steps.
#include
#include
#include
#include
#include
#include
#include
#include
#include
constint numwords = 34;
void DrawBody(int bodysize);
usingnamespacestd;
constint WORDSIZE = 6;
constint BODYSIZE = 6;
int main(int argc, constchar * argv[])
{
ifstream wordlist;
wordlist.open("wordlist.txt");
if (!wordlist)
{
cout << "couldn't find word list";
return1;
}
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
{
if (userGuess == wordA[i])
{
correctA[i] = true;
foundone = true;
numCorrect++;
}
}
if (not foundone)
bodyCount++;
cout << "bodycount = " << bodyCount << endl;
DrawBody(bodyCount);
for(int i=0; i
if (correctA[i])
cout << wordA[i];
else
cout << "_";
cout << endl;
}
if (bodyCount >= BODYSIZE)
cout << "you lose";
else
cout << "you win";
return0;
}
void DrawBody(int bodysize)
{
cout << "|-----|"<
switch (bodysize){
case1:
cout <<"| O"<
cout <<"| "<
cout <<"| "<
cout <<"| "<
cout <<"| "<
break;
case2:
cout <<"| O"<
cout <<"| |"<
cout <<"| "<
cout <<"| "<
cout <<"| "<
case3: cout <<"|"; break;
cout <<"| O"<
cout <<"| /|"<
cout <<"| "<
cout <<"| "<
cout <<"| "<
break;
case4:
cout <<"| O"<
cout <<"| |"<
cout <<"| /|\\"<
cout <<"| "<
cout <<"| "<
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