How to put "game over" at the end of my trivia game when the last question is answered. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to put "game over" at the end of my trivia game when the last question is answered.

My java code trivia game runs and plays perfectly until it gets to the last question. As soon as I answer the last question (54 of them) it comes up and says that it has "unexpectedly". I know this is because I don't have anything in my code to stop the program, so I tried an if/else statement in the update question method but it didn't do anything. Can someone tell me how to end the app with a "game over" statement or something? private void updateQuestion() { mQuestionView.setText(mQuestionLibrary.getQuestion(mQuestionNumber)); mButtonChoice1.setText(mQuestionLibrary.getChoice1(mQuestionNumber)); mButtonChoice2.setText(mQuestionLibrary.getChoice2(mQuestionNumber)); mButtonChoice3.setText(mQuestionLibrary.getChoice3(mQuestionNumber)); mAnswer = mQuestionLibrary.getCorrectAnswer(mQuestionNumber); if (mQuestionNumber > 56) { System.out.println("Game Over!"); }else{ mQuestionNumber++;

13th Nov 2017, 8:42 PM
Marcia Wilson
3 Answers
+ 2
Thank you so much!
14th Nov 2017, 5:51 AM
Marcia Wilson
+ 3
I suggest you use while loop instead
14th Nov 2017, 5:38 AM
Dennoh Peter
Dennoh Peter - avatar
+ 2
Welcome leave a like 😆😆
14th Nov 2017, 5:52 AM
Dennoh Peter
Dennoh Peter - avatar