java - Mastermind game if statement problems -
i trying make when 2 or more of if statements work dont both print instead 2 in correct spot or more more works. im not sure if im suppose make more if statements of if suppose use statement or forloop.
//if statements if (gameboard[0] == secret_code[0]) { system.out.println ("you have 1 in correct spot"); } if (gameboard[1] == secret_code[1]) { system.out.println ("you have 1 in correct spot"); } if (gameboard[2] == secret_code[2]) { system.out.println ("you have 1 in correct spot"); } if (gameboard[3] == secret_code[3]) { system.out.println ("you have 1 in correct spot"); } } }
the solution "in words"
instead of checking whether code correct in each spot , printing immediately, consider creating variable count number of times peg has been correct. don't print until know value of variable has taken consideration of elements of secret_code (a way (the "right" way)) loop through secret_code array , use new variable count each time code correct.
finally, print message user using variable holds information how many correct.
i won't include example code can sure implement , understand :-)
Comments
Post a Comment