This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
This is a number guessing game that allows 2-5 players. There is a random number generated for each player. I want the game to end as soon as the 1st player guesses the number correctly and ask for user input if they want to play again. Previously I was able to get the game to end after the 1st player to guess correctly by using system.exit but now I want to have the option for players to choose to play again and I was hoping someone can help me.
but now I want to have the option for players to choose to play again
Whenever you say that you want a part of a program to repeat, you should automatically think of using a loop of some kind and in fact enclosing the code that needs to repeat in this loop. In this situation where you don't know initially how many times the loop will occur, but you do know that it will occur at least one time, you should consider using a do-while loop.
Here is my code:
Your code is all left-justified and hard to read. As your goal is to get as many people as possible to read your code, you'll probably want to make it easier to read by editing this code so that it is properly indented.
Best of luck and again, welcome!
Joined: Oct 30, 2010
OK I really don't have any idea what I am doing but this is what I came up with so far. Sorry my indenting is terrible, I'm not sure how to indent correctly.
All I wish to know now is how I can get this program to stop asking for guesses after the first person guesses correctly. I tried the break command but there were errors and again, I don't have much experience. I want the program to ask if the user wants to play again after the first player guesses their number correctly.