I am trying to make it so when two or more of my if statements work they dont both print instead they just say two are in the correct spot or more it more works. Im not sure if im suppose to make more if statements of if i am suppose to use another statement or a forloop.
//If Statements
if (Gameboard[0] == Secret_code[0]) {
System.out.println ("You have one in the correct spot");
}
if (Gameboard[1] == Secret_code[1]) {
System.out.println ("You have one in the correct spot");
}
if (Gameboard[2] == Secret_code[2]) {
System.out.println ("You have one in the correct spot");
}
if (Gameboard[3] == Secret_code[3]) {
System.out.println ("You have one in the correct spot");
}
}
}
Instead of just checking whether the code is correct in each spot and then printing immediately, consider creating a variable which will count the number of times the peg has been correct. Then don't print anything until you know that the value of this variable has taken into consideration all of the elements of Secret_code
(a good way (the "right" way)) to do this would be to loop through the Secret_Code
array and use your new variable to count each time the code is correct.
Finally, print the message to the user using the variable which holds the information about how many are correct.
I won't include example code so you can be sure to implement and understand it yourself :-)