• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GuessGame with three classes (please help)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!


 
Ranch Hand
Posts: 51
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic