hi all
I have a question, how do you break out of a loop. i am building game and it is doing what it supposed to do but the problems is when the user enter a wrong answer it supposed to go back to the same question and repeat the question. the thing it is repeating the question but at the wrong level and wrong question and also it is in a loop. here is my codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | i= 1 ; for (i= 1 ; i <= 4 ; i++) { //get random numbers intvalue = 1 + randobj.nextInt( 25 ); intvalue2 = 1 + randobj.nextInt( 8 ); correctans = intvalue * intvalue2; wrongans = 25 + randobj.nextInt( 50 ); System.out.println(playername+ " round 1 " + " level " + i + " question " + i + " you are answered each question that correspond with an answer" ); System.out.println(playername+ " please multiply " +intvalue+ " * " + intvalue2); System.out.println( "A:" +correctans); System.out.println( "B:" +wrongans); ans = userinput.next().charAt( 0 ); if (ans == 'a' ) { System.out.println(playername+ " that answer is correct, you are doing just fine, keep it up " ); points += points + 450 ; System.out.println( "round 1" ); System.out.println( "level " + i); System.out.println( "question " + i); totalpoints += points; System.out.println( "total point are " + totalpoints); } else if (ans == 'b' ) { System.out.println(playername+ " yikess!!!!! that is so incorrect, come now,you can do better" ); points -= points- 225 ; System.out.println( "round 1" ); System.out.println( "level " + i); totalpoints -= points; System.out.println( "total points is " + totalpoints); count++; i= 1 ; while (count < 4 ) { System.out.println(playername+ " round 1 " + " level " + i + " question " + i + " you are answered each question that correspond with an answer" ); System.out.println(playername+ " please multiply " +intvalue+ " * " + intvalue2); System.out.println( "A:" +correctans); System.out.println( "B:" +wrongans); ans = userinput.next().charAt( 0 ); if (ans == 'a' ) { System.out.println(playername+ " that answer is correct, you are doing just fine, keep it up " ); points += points + 450 ; System.out.println( "round 1" ); System.out.println( "level " + i); totalpoints += points; System.out.println( "total point are " + totalpoints); } else if (ans != 'b' ) { System.out.println(playername+ " what is wrong you,come on now, inno daiz wrong" ); points -= points - 225 ; System.out.println( "round 1 " ); System.out.println( "level " + i); totalpoints -= points; System.out.println( "total points is " + totalpoints); } } |