Using the index as a counter?

So here is what I got following the guidelines of the challenge (without any incrementation). I was displaying the index + 1 originally, which works as well, but I’m sure the reasons are to help drive home the setter/getter methods.

//in Main.cpp
void PlayGame()
{
	
	int MaxTries = BCGame.GetMaxTries();
	int CurrentTry = BCGame.GetCurrentTry();
	
	for (int i = 0; i < MaxTries; i++)
	{
		PrintGuess();
		std::cout << "Try " << CurrentTry << ". Enter your guess." << std::endl << std::endl;
	}
}
//in class
int FBullCowGame::GetCurrentTry()
{
	return MyCurrentTry;
}
//and MyCurrentTry initialized to 1

Good catch. Since the index is not used for anything but counting tries, you could also start from 1 (and change the termination condition to == MaxTries).

I think when PlayGame is more elaborate, there might be a change in structure here. I am thinking about when some guesses are rejected as incorrectly formed without counting them as tries.

For example – and only for example, in my version, the FBullCowGame object keeps track of the state of play, so the tallying of good tries is inside the class. But this all comes later, and your mileage can vary.

Privacy & Terms