the mastermind game cannot show the result 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!!


}[/code]
Last edited on
I think rightpostion and rightnumber need to be reset to 0 after each round.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// the for loop is unnecessary around this code, guess it is a relic of other attempt
// assume rightnumber and rightpostion are both 0 each time this code is run
        if  (input[0] == number[0]){
			rightnumber ++;
			rightpostion ++;}
		if (input[1] == number[1]){
			rightnumber ++;
			rightpostion ++;}
		if (input[2] == number[2]){
			rightnumber ++;
			rightpostion ++;}
		if (input[3] == number[3]){
			rightnumber ++;
			rightpostion ++;}

// at this point of the code rightnumber == rightpostion

	    if ((input[0] == number[1]) || (input[0] == number[2]) || (input[0] == number[3])) 
            rightnumber ++;
         else if ((input[1] == number[0]) || (input[1] == number[2]) || (input[1] == number[3]))
            rightnumber ++;
         else if ((input[2] == number[1]) || (input[2] == number[0]) || (input[2] == number[3])) 
            rightnumber ++;
         else if ((input[3] == number[1]) || (input[3] == number[2]) || (input[3] == number[0])) 
            rightnumber ++;

// at this point of the code either rightnumber == rightpostion or rightnumber = rightpostion+1 


EDIT: duplicate http://www.cplusplus.com/forum/beginner/60920/
Last edited on
Topic archived. No new replies allowed.