For Loop Clarification

I am really having trouble grasping certain parts of this function so i will break it down to my knowledge and please correct me where i am wrong

so the code calls out to the function my current try and it increments its value plus one every time it loops thru.

then it creates a variable for bullcowcount for the struct to take account and start to take count ?

it creates a variable based on the length of my hidden word and it assigns it to the variable hiddenwordlength.

from there it starts to loop thru with a temp variable called MHWchar which starts off at = 0 which it runs thru and loops thru it until its equal or less than the hidden word length and incrementing MHWchar value plus one every time it doesn't equal to it.


then it does the same thing but with a variable called Gchar

then this is where I am most confused. it takes the players to guess input (Guess [Gchar]) and so what it does there is it takes the players input guess variable and it will iterate from 0 to the length of the word one digit at a time. creating a numeric code which is represented in the value of each letter in the alphabet which could be lets say 1234 if my word was = bcde = 1234
and so it would take these digits and do the same but with my hidden word [MHWChar] which if my word was bcde = 1234 would equal the same as my guess and so then if those numeric values are equal in which this example it is and so it would increment my bull count++, and so its basically taking whatever string guess is and running it thru the for loop under GChar and so it create a iteration for each digit and compare it to each other and creating a plus count in the bulls++ count in the struct
if (Guess [GChar] == MyHiddenWord[MHWChar])
is actually taking my guess word and running thru the Gchar for loop and breaking it down into iterations is that correct?
then it does the same thing but for the hidden word compares each of its numerical values iterations if they match it increments bull++ if not it does cows.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


      FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
	//incriment the turn number 
	MyCurrentTry++;
	// setup a return variable
	FBullCowCount BullCowCount;
	

	//loop through all letters in the guess
	int32 HiddenWordLenght = MyHiddenWord.length();	
	for (int32 MHWChar = 0; MHWChar < HiddenWordLenght; MHWChar++){
		//compare letters against the hidden word
		for (int32 GChar = 0; GChar < HiddenWordLenght; GChar++){
		//if they match then 
			if (Guess [GChar] == MyHiddenWord[MHWChar]) {
				 
			if (MHWChar == GChar) {//if theyre in the same place
				BullCowCount.Bulls++;// increment bulls
				}
					 
				else {
					BullCowCount.Cows++;//incriment cows  
I thought you understood it.

You seemed to at the end of your previous thread.
http://www.cplusplus.com/forum/beginner/248526/

Again I say, add debug prints anywhere you like to observe how the loops process your strings.

Your poor indentation skills are not helping you understand things either.

> FBullCowCount BullCowCount;
Does the FBullCowCount constructor initialise the .Bulls and .Cows members to zero?
Because if it doesn't, you're incrementing garbage in your loops, and that's going to confuse you.


> for (int32 GChar = 0; GChar < HiddenWordLenght; GChar++){
> if (Guess [GChar] == MyHiddenWord[MHWChar])
GChar should be limited by Guess.length(); unless you have some other way to ensure that the guess is always the same length as the hidden word.




No i didnt understand just one tiny part of it really which would be this



if (Guess [GChar] == MyHiddenWord[MHWChar])

i guess the if statement and the equal portion of it but is the GUESS [GCHAR] Portion is what gets me here so i understand that my Gchar is an if statement but what i am trying to have validated is the what its doing which in my lame terms is its taking my Guess variable and using that as its int 32 to create the digit place values for each string value inside the guess string is this pretty much right I know i need to enhance my vocabulary and terms but I am just at home learner trying to pick it up thanks again
If guess is "hello" and hidden word is "world", what answers do you expect for cows and bulls?
Topic archived. No new replies allowed.