java - Monty Hall Game -


I'm currently a new programmer in the Java learning process. I found a game based on this game. Let's get a deal Do & amp; Monty Hall (problem) and I have been having issues with the logic for this code. Everything is working fine except that I can not seem to get the user_door to switch to the other door and to determine whether they are a winner if someone can help me understand that I Thank you for knowing this opportunity, thank you! import java.util.Random; Import java.util.Scanner; Public square gameshow {public static zero main (string [] args) {scanner scan = new scanner (System.in); Random generator = new random (); // Start variable variable user_door, open_door, other_door, prize_door; // Generate random value 1-3 prize_door = generator.nextInt (3) +1; Open_door = prize_door; Whereas (open_door == prize_door) {open_door = generator.nextInt (3) +1; } Other_door = open_door; While (other_door == open_door || other_door == prize_door) {other_door = generator.nextInt (3) +1; } // game Game.out.println ("Welcome to Game Show! ***"); System.out.println ("Select the door (1, 2, or 3):"); User_door = scan.nextInt (); // User Validation (user_door> gt; 3 || user_door & lt; 0) {System.out.println ("Please select door 1, 2, or 3"); User_door = scan.nextInt (); } Else if (user_door == 1 || user_door == 2 || user_door == 3) {// game system turn on. Out.println ("\ nIn a moment, I'll tell you where the award is located,"); System.out.println ("But first I'll show you what's behind one of the other doors"); // Continue the dialogue system. Out.println ("\ n Back +" OpenOddoor + "is Goat!); System.out.println (" You chose the door number "+ user_door); System.out.println (" \ n Do You Know Your Door Y / N) Want to switch? "); // User input Yes or display a four user = scan .net (.) Characte (0); // if the user inputs the nested statement with the statement (if the user replay = = 'Y') {user_door = other_door;} While (user accountability! = 'Y' and user; answer! = 'N') using {// Yes Validation System.out.printline ("Please enter y / n"); UserReply = scan.next (). Fourat (0);} System.out.println ("The prize is behind the gate number:" + prize_door) ; // Check if the user has won or lost (user_door == prize_door) {System.out.println ("Congratulations! You won the prize!");} Else {System.out.println ("Sorry, you "); I agree with what Shrikant had said above, which is unavailable which is the part where you examine the user's answer. "If" and change the "while" statement would help to resolve the issue with your door switch.

Earlier

  if (user reeply == 'y') {user_door = other_door; } While (user accountability! = 'Y' and user; answer! = 'N') {// user validation system.out.printline ("please enter y / n"); UserReply = scan.next (). Fourat (0); }   

Change to ; (User reply! = 'Y' & Answer User! = 'N') {// User Validation System Out.println ("please enter y / n"); UserReply = scan.next (). Fourat (0); } If (User Repli == 'Y') {user_door = other_door; }

Check the way you were doing this for the first time only if a character was recorded if they did it wrong and tried to redo it, then this door can not change Because you were the last of that part of the program.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -