Hi,
I have written a number guessing game in java, where the user can select the number of guesses and the range of random numbers. It will display higher and lower and correct however it will not calculate when the number of guesses has been exceeded and the appropriate message. I believe the error is in the for loop in my game class.
public abstract class Game {
protected int guess;
protected int random, range;
private String msg;
public abstract void setup(int r, int g);
public String compareGuess(int userRandom) {
int i;
for (i = guess; i > 0; i--) {
if (userRandom < random) {
msg = "Higher";
} else if (userRandom > random) {
msg = "Lower";
} else if (userRandom == random) {
msg = "Correct";
} else {
msg = ("Sorry the correct number was " + random);
}
}
return msg;
}
}