My For Loop Code

So I put in “WORD_LENGTH” as my condition to remove the use of a magic number, but also because I was thinking that eventually we would make a function of if/else statements that would determine the number of guesses based off of word length, and so I would replace “WORD_LENGTH” with the variable that would result from that function (correct me if I’m wrong). Anyways, here’s my code:

int main() {

	PrintIntro();
	for (int count = 0; count <= WORD_LENGTH; count++) {
		GetAndPrintGuess();
	}

	cout << endl;
}

With “GetAndPrintGuess” as it was in previous videos.

This will count 1 too many, for example WORD_LENGTH is 3, that would go 0, 1, 2, 3 which is 4 times, either start at 0 and do < or 1 and <=

Privacy & Terms