0

here is my code in java: i used nested do-while loops

do{ //Level hard

     do{ //level meduim
     
       do{  //level easy
   

 //LEVEL EASY 

if (num==1){
 //1st question
//[logic displayed]

  
 System.out.println("Would you like to play again? Type in Y for yes or N for no ");

   retake = kbd.nextLine();
  } while ( retake.equalsIgnoreCase("Y"));

System.out.print("Bye! Come back soon! ^-^");

 //level medium
 //[logic is here]

 
 System.out.println("Would you like to play again? Type in Y for yes or N for no ");

   retake = kbd.nextLine();
  } while ( retake.equalsIgnoreCase("Y"));

System.out.print("Bye! Come back soon! ^-^");

 //level hard 
 //[level hard is the same thing as the ones on top 
 
    System.out.println("Would you like to play again? Type in Y for yes or N for no ");

    retake = kbd.nextLine();
   } while ( retake.equalsIgnoreCase("Y"));
     }
   }

the thing is when I try to retake the quiz in the hard level, it wont work. it would just display this:

   Would you like to play again? Type in Y for yes or N for no 
   Bye! Come back soon! ^-^Would you like to play again? Type in Y for yes or N for no 

but the strange thing is when I type N (no to retake) it would start the quiz the hard level how can I make it work? and why is it wrong? (please help this is due today)

  • Strange design with three nested loops - that means that if you want to retake the hard level you also must take the easy and the medium level again. – Thomas Kläger Jan 22 '22 at 17:31
  • 1
    Does this answer your question? [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – Thomas Kläger Jan 22 '22 at 17:32
  • Just a wild guess: teh code that you don't show reads more input through `kbd` and does so using `next()` / `nextInt()`. If this is the case then please read the linked duplicate carefully. – Thomas Kläger Jan 22 '22 at 17:34
  • i took the easy and meduim level before the hard level but it still won't work. i want the user to be able to retake the quiz in the level they choose. and sorry but I forgot to say this, In my code, the user chooses which level they want, by typing 1, 2 or 3. so when the user chooses 3 (the hard level) it won't display and just say "Would you like to play again? Type in Y for yes or N for no Bye! Come back soon! ^-^Would you like to play again? Type in Y for yes or N for no" – Aya Abdalla Jan 22 '22 at 18:00

0 Answers0