This solution seems to work-Opinions?

After about 2 hours of trying out different conditional statements, i found a working solution.
I would like to know what opinions anyone may have regarding my solution, any feedback is appreciated.

my code here

You might want to think about making the 5 you used into a variable. that way you only have to change the value in one place and don’t have to hunt down all the places in your code that would need to be updated.
e.g.
int32 maxLetterCount = 5;

Cool, thank you for the tip. I forgot all about the “magic numbers”.

it turns out i dont need to do so many comparisons. particularily with
else if ((MyHiddenChar == 5)||(MyGuessChar == 5))

it works the same if
else if (MyHiddenChar == HiddenWordLength)

new code here

here’s mine

If your code works then cool and I know this is a couple of months old so you probably are way past this but:

As far as simplifying code goes, I’m not understanding why you have the breaks in your code. First I noticed that in your second for loop you are comparing MyGuessChar to the length of the guess word and not the hiddenword. Which means essentially that the player could keep the game going indefinitely as long as that player inputs a bigger word each time. I’m assuming that is why you have the first break there to keep that from happening. However, if the player was playing properly the break is redundant since the for loop would end before ever getting to the break statements and if you used the length of the hiddenword instead of the length of the guess word you really don’t need the breaks since your taking the ability away from the player to control how long the game goes. Lastly your second break is also unnecessary since it will never happen because when MyHiddenChar == HiddenWordLength the outer for loop will end. Maybe I’m not seeing something though. Hope everything is working out well.

Wow, its interesting how sloppy my code is looking back on it. Thanks for the in depth review. I was just starting to go through this section a second time.

This was my first programming project, what you see, i certainly did not first time going through.

1 Like

Here’s my version, I tried to see if I could use a ternary operator, and it makes the code look so much neater.

Privacy & Terms