hi
I am trying to build this multiplication game program, well it is the same multiplication game as before. It seems to be working fine but it is not giving me the exact output.

first: - when the user enter the correct answer the first time, the game stop when it supposed to at least goes on to the second player.

second: - when the user user enter the wrong answer, it supposed to loop back to give the first user(player) another chance to get the correct answer. (the player has three tries).

third: - but when the first user answer the wrong answer, it goes to the second user, which is good but the second user supposed to come after the first user exhausted all their chances.

fourth: - when the second user answer incorrectly, it gives the second user a chance to get the answer correct and then it hit the first statement for the first user.

how can i fix this and what can i do to fix it

here is my codes and the output.

   //while loop prompting the user to state which level of the game they would like to play
        while(countlev_easy == 'e' ||countlev_easy == 'E' || countlev_med == 'm' || countlev_med == 'M'|| countlev_hard == 'h'|| countlev_hard == 'H')
        {

           System.out.println("which level would you like to start with");
           System.out.println("choose: e ");
           System.out.println("choose: E");
           System.out.println("choose: m");
           System.out.println("choose: M");
           System.out.println("choose: h");
           System.out.println("choose: H");
           level = userinput.nextInt();


        }

        //here is where you are asking the user for information pertaining to their name and age

          System.out.println("hi can you  tell me your name");
          String user1name = userinput.next();
          System.out.println("what a lovely name, my dear " +user1name+ " nice love");
          System.out.println("what is your age " + user1name);
          int user1age = userinput.nextInt();

        while(user1age < 6 || user1age > 12)
        {
           System.out.println("incorrect age, you cant play this game " +user1name);
           break;

        }
        while(user1age > 6 || user1age < 12)
        {
          System.out.println("hi please re-enter your again " +user1name);
          user1age = userinput.nextInt();


          System.out.println("boom you can play");
          break;
          }

          System.out.println("hi what is your name");
          user2name = userinput.next();
          System.out.println("wonderful, you have such unique name "+user2name);
          System.out.println("hi how old are you " +user2name);
          user2age = userinput.nextInt();

          while(user2age < 6 || user2age > 12)
        {
          System.out.println("incorrect age " +user2name+ " you cannot play this game, okay");
          break;
        }
          while(user2age >6 || user2age < 12)
        {
          System.out.println("please re-enter your age "+user2name);
          user2age = userinput.nextInt();

          System.out.println("perfect, just the age, you can now play");
          break; 

        }
          System.out.println(user1name+ " you are the first one up");

          Random generator = new Random();
          int num1 = (int)(Math.random()*12);
          int num2 = (int)(Math.random()*12);
          int z = num1 * num2;


        while(quest1 <= 12 && quest2 <=12)
        {


        {
            System.out.println(num1+ "*"+ num2 + "=");
            ans = userinput.nextInt();

        }

        if(ans == num1 * num2)
        {
          System.out.println(user1name+"  lovely,  correct " + " you gain 150 point " + " you get a chance to move to the next level");
          sumpts+=150;
          quest1++;
          break;
        }
        else if(num1 * num2 != ans)
        {
          System.out.println(user1name+ "  well, that's interesting "+ "you got incorrect "+ "  you just lost 75 points " + " you cannot move on to the next level");
          sumpts -= 75;
          quest1++;
          numtries++;
        }

        System.out.println(user2name+" it is your turn now");


          num1 = (int)(Math.random()*12)+2;
          num2 = (int)(Math.random()*12)+2;
          z = num1 * num2;


        while(quest1 <= 12 && quest2 <=12)
        {
            System.out.println(user2name+" how much is " + num1 + "*"+ num2+ "=");
            ans = userinput.nextInt();
            break;
        }
        if(ans == num1 * num2)
        {
            System.out.println(user2name+" awesome!!!!, that's so correct "+ "you gain 175 point" + "you can move on the next level");
            sumpts +=150;
            quest2++;
            numtries++;
            break;
        }
        else if(num1 * num2 !=ans)
        {
            System.out.println(user2name+" that so incorrect, try again "+ " you lost 75 point and may not be able to move to the next level");
            sumpts -=75;
            quest2++;
            numtries++;
        }
        here is the output
        hi can you  tell me your name
annisha
what a lovely name, my dear annisha nice love
what is your age annisha
5
incorrect age, you cant play this game annisha
hi please re-enter your again annisha
10
boom you can play
hi what is your name
glen
wonderful, you have such unique name glen
hi how old are you glen
13
incorrect age glen you cannot play this game, okay
please re-enter your age glen
11
perfect, just the age, you can now play
annisha you are the first one up
0*7=
7
annisha  well, that's interesting you got incorrect   you just lost 75 points  you cannot move on to the next level
glen it is your turn now
glen how much is 4*9=
32
glen that so incorrect, try again  you lost 75 point and may not be able to move to the next level
4*9=
36
annisha  lovely,  correct  you gain 150 point  you get a chance to move to the next level
BUILD SUCCESSFUL (total time: 53 seconds)

Starting at the beginning...
line 2 starts a loop using the value of various count variables, but these are never changed in the loop. So either it will execute zero times, or it will loop forever.
Similarly the next loop (line 25), except because it has an unconditional break in it it will execute either 0 or 1 times.
The loop on line 31 is slightly better in that it does change the value of the variable in the while clause, but again it has an unconditional break, so it will only ever execute 0 or 1 times.

Ok, that's enough for now! Go though all the other loops to see if you have made the same mistakes there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.