Identifier Undefined during debugger

When trying to run debugging

identifier “MHWChar” is undefined

MHWChar should be declared as part of your first for statement that iterates through each letter:

for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)

if its something else, could you post your complete for loop?

Here is what my entire loop looks like (with a few changes)

	//loop through all letters in guess
	int32 HiddenWordLength = MyHiddenWord.length();
	for (int32 MyHWChar = 0; MyHWChar < HiddenWordLength; MyHWChar++) 
	{
		//compare letters against hidden word
		for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
		{
			//if they match
			if (Guess[GChar] == MyHiddenWord[MyHWChar]) 
			{
				//if theyre in the same place
				if (MyHWChar == GChar) 
				{
					BullCowCount.Bulls++;//increment bulls
				}
				else 
				{
					BullCowCount.Cows++;//increment cows
				}
			}
		}
	}
	return BullCowCount;
}

I’m having the same issue, exactly the same code as the instructor. Could the problem be due to using a later compiler? Probably unlikely… But I’ve gone over my code several times and can’t figure out how to fix it.

Hi there, I had this issue and it took me a while to work out what it was, but it turned out I had erroneously added a semicolon at the end of both for loops:

for (int32 i = 0; i < HiddenWordLength; i++)**;**
	{
		// compare letters against the the hidden word
		for (int32 j = 0; j < HiddenWordLength; j++)**;**
		{
			// if they match
			if (Guess[i] == MyHiddenWord[i])
			{
				
				if (i == j) // if they're in the same place
				{
					BullCowCount.Bulls++; // increment bulls
				}
				else
				{
					BullCowCount.Cows++; // must be a cow
				}
			}
		}
	}

If you have done the same, removing the semicolons at the ends of the for loops (before the definitions), should fix the issue.

Apologies for just pasting in my loop, I’m new at this :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms