the mastermind game cannot show the results in the round 2 or above

The first round of the game seems okay. The game will generate the result but >1 round , the result wont be show.

And the is another mistake I found.
For example, when the random no. is 5134 and my guess is 5143
the game will generate the code O O #, which is wrong, it should be O O # #.
But I cannot find out the reason.


Thank you so much!!

Last edited on
There's three things wrong with this:
Line 30:
for(counter>0; counter<=4; counter++)The first argument in a for loop should be an assignment - you have included a comparison. Effectively, you could completely remove the first argument with no effect on the code.

Line 85-86:
You forget to reset the value of rightposition and rightnumber, they should be reset each time just before you increment them.

Line 86:
You have a for loop that results in you outputting the text four times:
MasterMind (For checking: 5 1 3 6)
Enter four digits (1-6) seperated by a space
--------------------------------------------
Round 1:
Enter Guess: 1 2 3 4
O #
--------------------------------------------
O O # #
--------------------------------------------
--------------------------------------------
--------------------------------------------

As you can see, I had one number in the right position (the 3) and one right number not in the right position (1).
Second time it looped, it increaced both values by 1, thus displaying OO##.
Third time the counter hit three right numbers and three right positions, which doesn't match any of your output conditions.
Etcetera etcetera etcetera.

Any more guesses would add (because you don't reset the rightnumber and rightposition values) four (because of the for loop) times what they should.
thank you so much!!
the task have done!!
thanks so much!
I changed i<4 to i<1!
Topic archived. No new replies allowed.