Ok so I am writing a program where the user enters a number and the computer guesses the number. I'm having trouble with my elseif statement inside of my while loop. The problem is it prints out "guess higher" but the computer does not always guess higher. I'm not sure how to go about this problem. Any advice is appreciated here is the code
while(computerGuess != userGuess) {
if(computerGuess > userGuess) {
System.out.println("Guess lower: ");
computerGuess = guess.nextInt(userGuess);
System.out.println(computerGuess);
}else if(computerGuess < userGuess) {
System.out.println("Guess higher: ");
computerGuess = guess.nextInt(101);
System.out.println(computerGuess);
}
amountTries++;
}
Aucun commentaire:
Enregistrer un commentaire