Results 1 to 6 of 6
Thread: Hi Lo Game
- 10-21-2010, 11:56 PM #1
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
Hi Lo Game
Hi guys !!! how can i make a loop that will continually accept and check user input , if wrong prompts for another guess.
Java Code:import java.util.Scanner; import java.util.Random; public class HiLo { public static void main(String[]args) { int c,b,d,e; Random generator = new Random(); int a = generator.nextInt(100); Scanner scan = new Scanner(System.in); System.out.println("Guess any number between 0 -100 (inclusively) "); c =scan.nextInt(); b =generator.nextInt(100); while (c != b) { System.out.println("WRONG GUESS AGAIN!!!!" +"(" + b+ ")" ); e = scan.nextInt(); Scanner s2 = new Scanner(System.in); d = generator.nextInt(100); } } }// CODE COMPILES FINE BUT DOESNT WORK CORRECTLY.IT WONT GENERATE A DIFFERENT RANDOM NUMBER
- 10-22-2010, 12:08 AM #2
In the while loop you are using variable 'e' as the user input. In the while loop declaration you are checking variable 'c' which is not changing in the loop. So change 'c' to 'e' and then initialize 'e'.
Sincerely, Joshua Green
Please REP if I help :)
- 10-22-2010, 02:12 AM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
Hey buddy thanks for the feedback i tried doing as you said and i got the exact same results heres what i got so far
Java Code:import java.util.Scanner; import java.util.Random; public class HiLo { public static void main(String[]args) { int c,b; int d=0; int e = 0; Random generator = new Random(); int a = generator.nextInt(100); Scanner scan = new Scanner(System.in); System.out.println("Guess any number between 0 -100 (inclusively) "); e =scan.nextInt(); b =generator.nextInt(100); while (e !=b ) { System.out.println("WRONG GUESS AGAIN!!!!" +"(" + b+ ")" ); Random generator1 = new Random(); Scanner s2 = new Scanner(System.in); e = s2.nextInt(); d = generator1.nextInt(100); } } }
- 10-22-2010, 02:19 AM #4
Now you have a variable 'd' inside your loop instead of 'b'. Are you trying to make it so you can keep guessing without the program terminating?
Sincerely, Joshua Green
Please REP if I help :)
- 10-22-2010, 02:35 AM #5
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
Ah ha Thanks for the help..Got it running now.
D
D
D
D:eek::cool:
- 10-22-2010, 03:08 AM #6
Similar Threads
-
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
game code for any game
By deathnote202 in forum Java GamingReplies: 4Last Post: 06-10-2010, 08:06 AM -
can someone help me with this game??
By amalina in forum New To JavaReplies: 1Last Post: 08-24-2009, 05:59 AM -
Game 21
By aRTx in forum Advanced JavaReplies: 3Last Post: 04-04-2009, 12:33 AM -
2D strategy game or 2D war game
By led1433 in forum Java 2DReplies: 5Last Post: 02-10-2009, 06:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks