Need help with riddles prog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ImortalSorrow
    New Member
    • Feb 2008
    • 13

    Need help with riddles prog

    Hey, I hope you can help me with a prog i'm making. Everything is working well except a part where i want to repeat the riddle if the answer isnt correct. here's the bit of the bode where i need help
    Code:
         
    System.out.println("Riddle:blablabla");
        riddleanswer = scanner.nextLine();
        
        if (riddleanswer.equals("2") || riddleanswer.equals("two")) {    	
        	    System.out.println("Great!");
        } else {
        	System.out.println("Upss..");
    well this way it would just finish the code once you get the wrong answer, but i need 2 repeat the riddle 2 be able 2 try again.

    Thanks
  • ImortalSorrow
    New Member
    • Feb 2008
    • 13

    #2
    Please need help!!...

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Maybe a do { ... } while( ... ); loop can be of help here?

      kind regards,

      Jos

      Comment

      • ImortalSorrow
        New Member
        • Feb 2008
        • 13

        #4
        ohh i get it, but can you help me with the code? im noob in programming so i dont exactly know what to put in the brackets you made. in this case what should i exactly do? should i erase the "if" and the "else" and do other code?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by ImortalSorrow
          ohh i get it, but can you help me with the code? im noob in programming so i dont exactly know what to put in the brackets you made. in this case what should i exactly do? should i erase the "if" and the "else" and do other code?
          A hint: your lines 1 and 2 should go between those curly brackets. The condition
          in your if statement should go between the parentheses.

          kind regards,

          Jos

          Comment

          • ImortalSorrow
            New Member
            • Feb 2008
            • 13

            #6
            ohh thanks a lot! ill try it

            Comment

            • ImortalSorrow
              New Member
              • Feb 2008
              • 13

              #7
              ohh god i still cant do it.. i donno what i did wrong. i'll copy the entire code for you to see if there's anything wrong. hope some1 can help..
              Code:
              import java.util.Scanner;
              
              class TheRiddle {
                      
                
                  public static void main(String[] args) {
                  	Scanner scanner = new Scanner(System.in);
                  	String playername;
                  	String riddleanswer;
                  	char yesorno;
                  
                  		
                  System.out.println("enigma!");
                  System.out.print("write your name: ");
                  playername = scanner.nextLine();
                  System.out.println("");
                  System.out.println("hey " + playername + ". blablabla" );
                  System.out.print("press 'Enter' when ready");
                  scanner.nextLine();
                  System.out.println("");
                  
                  do {System.out.println("riddle nÂș 1..blablabla");
                  riddleanswer = scanner.nextLine()}
                  
                  while (if (riddleanswer.equals("2") || riddleanswer.equals("two") {    	
                  	    System.out.println("nice!");
                  } else {
                  	System.out.println("Upss.."));
                  	
              	
                  }
              System.out.print("press 'Enter' to continue");
                  scanner.nextLine();
                 System.out.println("");
                 System.out.println("2nd riddle...blablabla
                 riddleanswer = scanner.nextLine();
                 			
                 scanner.nextLine();
                 System.out.println("");
              
              
              
                  }
                  	       	
                  	
                  	}
                  	   	
                 			}
              Same thing fot the second riddle...

              Thanks

              Comment

              • ImortalSorrow
                New Member
                • Feb 2008
                • 13

                #8
                C'mon Please Someone!!...

                Comment

                • ImortalSorrow
                  New Member
                  • Feb 2008
                  • 13

                  #9
                  Help needed over here!!!!....

                  Comment

                  • ImortalSorrow
                    New Member
                    • Feb 2008
                    • 13

                    #10
                    OMG can anyone in this bloody comunity help me please?!?!...

                    Comment

                    • Laharl
                      Recognized Expert Contributor
                      • Sep 2007
                      • 849

                      #11
                      First, please don't create multiple threads on the same problem, as it spreads out answers among the threads, leading to confusion both among our experts and at your end.

                      Second, this is a message board and it's a Saturday afternoon in the States, where I believe many of our users live. Message boards are by definition slower than, say, a chatroom. Also, because it is a weekend, people likely to be off having fun or doing errands rather than online.

                      To answer your question, look into while loops here .

                      Comment

                      Working...