So I'm supposed to make a 'how many jelly beans in the jar' guessing game. A few people guess and the winner is outputted while also showing how close or far they were.
I'm having trouble with the output of how far the user was from the number of jelly beans in the jar:
Code:do
{
// Enter guess
System.out.print(playerName[i] + ", Enter your guess between 1000 and 2000: ");
playerGuess[i] = input.nextInt();
} while (playerGuess[i] <= 1000 || playerGuess[i] >=2000);
}
int howClose = jellyNum - playerGuess.length;
And also it outputs everyone as being the winner:
Any tutorials I can watch or is this a small stupid problem I am not seeingCode:for (int i = 0; i < playerGuess.length; i++)
{
if (playerGuess.length == jellyNum)
{
System.out.println("\nWinner is " + playerName[i] + " who guessed " + playerGuess[i] + ". Spot on! That is the exact # of jelly beans in the jar!");
System.out.println("\nYou were " + howClose + " of " + jellyNum + " jelly beans");
}
else if (playerGuess.length > jellyNum || playerGuess.length < jellyNum)
{
System.out.println("\n Winner is " + playerName[i] + " with a guess of " + playerGuess[i] + ", only " + howClose + " jelly beans away! Congrats!");
}