This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes GuessGame with three classes (please help) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "GuessGame with three classes (please help)" Watch "GuessGame with three classes (please help)" New topic
Author

GuessGame with three classes (please help)

david torrance
Greenhorn

Joined: May 04, 2013
Posts: 3
Hello, I've been struggling with this program that keep running loop forever. It supposed be stop when player get the right guess number. I couldn't find what's wrong with my program So, please anyone could help me? It's due this Tuesday, May 7. THANK YOU!!


John Corkrend
Ranch Hand

Joined: Oct 27, 2012
Posts: 51

Please use code tags in the future so that your code is easier to read.








Besides that in your logic you should use .equals instead of ==. But I am not the most experienced so I may be wrong, if someone else on the forum would make sure that is right.
If there are any other errors please ask.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1752
    
    7

Hi, and welcome to CodeRanch!
I've edited your post to include code tags, which makes the code segments of your post a bit easier to read. You can read up how to UseCodeTags (<-click) to find out how this works.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1752
    
    7

Your program will only break from the loop if either player has made a correct guess.
The range for the number to guess is defined by this code segment:


While the number range a player can guess is defined by this code segment:


The problem is with these ranges. If you figure out what number ranges each of the code fragments can generate, you'll have solved your problem.
david torrance
Greenhorn

Joined: May 04, 2013
Posts: 3
Ah I thought there was nothing wrong with loop. You solved a problem that my program is now running without any errors and will use code tags next time. Thank you so much and this forum rocks! =D
 
wood burning stoves
 
subject: GuessGame with three classes (please help)
 
Similar Threads
IDE or bust?
Head First Java Book, Chapter 2
Please Help with Guessing Game (Head First Java)
Very new to java
GuessGame Errors From Head First Java