Using a method call vs. widening WORD_LENGTH's scope

You honestly didn’t have to define WORD_LENGTH outside of a method. Although it took a bit of thinking, I found out that you could still keep WORD_LENGTH’s scope, but make it accessible. By taking WORD_LENGTH outside of print_into(), defining WORD_LENGTH inside it’s own method, and by making both print_intro() and get_guess_and_print_back() void, I was able to do just that. Since print_intro() and get… weren’t really returning anything anyway due to std::cout, I figured that it was fine to leave them void.

Here’s some snippets of my code:

void print_intro();
void get_guess_and_print_back();

int main() {

print_intro();

get_guess_and_print_back();

return 0;

}

int word_length() {
constexpr int WORD_LENGTH = 5;
return WORD_LENGTH;
}

/*repeat the guess back to them/

void get_guess_and_print_back(){
string Guess = “”;

for (int count = 1; count <= word_length(); count++) {
	cout << "Enter your guess: ";
	getline(cin, Guess);


	
	cout << "\nOkay, so your first guess was " "'" << Guess << "'";
	cout << " right ?\nLet's see if we have a match.";
	cout << "\n\n.  .  .\n\n";
}
return;

}

Privacy & Terms