alright well i have already posted in the python forum part, now this question is the same one as the one i did for college level computer science but this is for university. any way im pretty sure i have it but before when it was working it would say that my first guess was closer but even though the computers randomly generated number was 87 it would say my first guess 12 was closer to my guess, but this is not right and i added a bit more to it to make it look nicer but after that it would stop at the if statements and would not do them, so im wondering if someone could just have a look at it and tell me what im doing wrong and hint me as to what i should do,
guess my number question:
import java.util.Scanner;
public class RandomGuess {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int randomNumber = (int) (Math.random() * 100 + 1);
System.out.println("I have chosen a number between 1 and 100. Try to guess it.");
System.out.println("Please enter in your first guess:");
int guess1 = sc.nextInt();
System.out.println("Please enter in your second guess:");
int guess2 = sc.nextInt();
System.out.println("Guess#1:" + guess1);
System.out.println("Guess#2:" + guess2);
if (guess1 == randomNumber) {
System.out.println("Good job! Your first guess:" + guess1 + " was exact to my number!");
} else if (guess2 == randomNumber) {
System.out.println("Good job! Your first guess:" + guess2 + " was exact to my number!");
} else if (guess1 > randomNumber && guess1 > guess2) {
System.out.println("The number was: " + randomNumber + " ." + " Your first guess was closer.");
} else if (guess1 < randomNumber && guess1 < guess2) {
System.out.println("The number was: " + randomNumber + " ." + " Your first guess was closer.");
} else if (guess2 > randomNumber && guess2 > guess1) {
System.out.println("The number was: " + randomNumber + " ." + " Your second guess was closer.");
} else if (guess1 < randomNumber && guess1 < guess2) {
System.out.println("The number was: " + randomNumber + " ." + " Your second guess was closer.");
}
}
}
im not sure what is worng so like i said, if someone or people just look it over, tell me what im doing wrong and hint me to what i should do.
thanks in advance,
strong guy :)