One of the several issues (other than attempting to call
main()
which is illegal in standard C++) is in this line:
|
string checkLength(guess, word_length);
|
That doesn't do what you intended.
Instead it attempts to create a string named
checkLength
which is a substring of guess. It starts at position word_length and continues to the end of the string. But what happens if the user types a string shorter than word_length ? Well, the requested start position is outside the string.
See std::string constructor (3).
http://www.cplusplus.com/reference/string/string/string/
What you could have put is either of these:
|
checkLength(guess, word_length);
|
or
|
string result = checkLength(guess, word_length);
|
There's a related, though different error inside function playAgain(). The line
int playAgain();
is a declaration, it doesn't call the function.
In addition, there's a problem with the recursive function calls, in particular when the function promised it would return a value, but didn't, sooner or later those recursive calls will unwind and the program could crash. If the function should return a value, make sure it
always does so. If necessary, add a
return "";
or
return 0;
just before the closing brace (depending on what type the function is returning).