I have a project that I am working on. It is a game where the computer generates a random number between 1-100 and you get 6 oppurtunities to guess the correct answer. Everything seems to run just fine. My only issue now is that the program is not displaying the correct if statements. I do not know if my if else statements are wrong or if the computer is choosing a new random number each time. I tried to test this new random number generation by printing and displaying "r" which you'll see in the code. Can anyone point me into the proper direction or give me any help. I think I am 95% done this thing after this. Thanks alot! (btw I have my print out of "r" as a comment right now) - for future reference how could i test this properly? Attached is a screenshot of the compiler. The random number is getting printed after "Please guess a number"
import java.util.*; public class project2 { public static void main(String[] args){ Scanner in = new Scanner (System.in); System.out.println("Welcome, I am thinking of a number between 1-100. Take a guess!"); System.out.print("Please enter your number: "); Random r = new Random(101); int actual = r.nextInt(); //System.out.print(r); int totalcount = 6; int gamecounter = 0; while ( gamecounter != totalcount) { int counter = 0; int turncount = 1; int guess = in.nextInt(); while (counter != turncount) { if ( guess < actual) { System.out.println("You guessed " + guess); System.out.println("Too Low");} if ( guess > actual){ System.out.println("You guessed " + guess); System.out.println("Too High");} else { System.out.println("You guessed " + guess); System.out.println("YOU'RE PSYCHIC!");} counter++; } gamecounter++; } System.out.println("Game Over Please Try Again"); } }