Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

need help logical errors cant figure out

java

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 26 November 2015 - 09:13 PM

hi everyone

oh gosh imma know allyuh probably get fed up of me. I am building this game, well it is the same game as in my last post. I decided to delete everything and do it over just to figure out my logical error and boi when i really think i did, i could not have been more wrong.

i finally have a fair idea on how the game should be build. it have 3 game round. and in each rounds. they are 10 random numbers should be generated.
round 1 must have 4 question. random numbers which should be randomized. it is a multiple choice game(round 1 - addition round)
round 2 must also have 4 question which also should be randomized (round 2- subtract round)
round 3 must have 2 question random numbers which should be randomed (round 3 - division round)
i figure out how to get the levels for round one: round 1 levels should be from 1-4, round 2 levels - 5-8 and round 3 level 9-10
i figure out how to get round 1 levels from 1-4, it is round 2 and 3 levels iam trying how to get it to say 5-8 and 9-10

another problem am having is that it have logical errors because it is not running how it supposed to run. I used a for loop where it supposed to generate for 4 question from the random numbers. but is not generated the 4 question, it give only one question and it jump to round 2. i
it supposed to show the scores that i hve added and the total scores, it is not doing that, it just jump straight to round 2.
can you tell me where and how i can fix this because i have less than a few weeks to hand in. i havnt finished coding as yet, was just checking ever so often to see how it is running. here is my codes and the out put.

System.out.println("Welcome to Aunty Luz's Multiple Choice Math Game");
        System.out.println("The game consist of 3 round with 6 level");
        System.out.println("The age limit is 8 - 13 years ");
        System.out.println("A player wins the game if all questions are answerred correctly");
        System.out.println("The player loses the game if they run out of chances");
        System.out.println("Each player has 4 chances");
        System.out.println("Each correct answer is rewarded with a maximum of 350 points");
        System.out.println("Each incorrect answer will lose half of the alloted point given ");
        System.out.println("A report is submitted at the end of the game");
        System.out.println("A player only win the game if all 10 question are answered correctly");
        System.out.println("A player loses the game if the age is entered incorrectly or if the player ran out of the chances given");
        System.out.println("okay students, I hope that I have made myself very clear");
        //input the rules and regulation of the game 
        System.out.println("+*+*+*+*+*+*+*+*+welcome to the game 1+*+*+*+*+*+*+*+");
        System.out.println("Hi what is your name");
        playername = userinput.next();
        System.out.println(playername+" your name is very unique, my dearest");
        System.out.println(playername+" how old are you");
        playerage = userinput.nextInt();
        //asking for the user name and age
        if(playerage < 8 || playerage > 13)
        {
            System.out.println("you have entered an invalid age");
            System.exit(0);
            //this is used for the userage. the game will exit if the wrong age is entered
        }
            //this looping is checking to see if the user enter the correct age
        else if(playerage >= 8 && playerage <= 13)
        {
            System.out.println(playername+" come let's play");
            //this is indicating that the user can play after inputting the correct age
        }
        for(i = 1; i <=4; i++)//getting the four numbers to be generated
        {
            //get random numbers
            rand  = 1 + randobj.nextInt(25);
            rand2 = 1 + randobj.nextInt(8);
            correctans = rand + rand2;//this is to hold all the correct answer
            incorrectans = 25 + randobj.nextInt(50);//this is to hold all the wrong answer
            System.out.println(playername+" round 1,"+ " level "+ i+ " Question "+i+ " can you match the letter to the correct answer");
            System.out.println(playername+" what is "+rand+ " + "+ rand2);
            System.out.println("A:"+correctans);
            System.out.println("B:"+incorrectans);
            choice = userinput.next().charAt(0);
        if(choice == 'A' || choice == 'a')
        {
            System.out.println(playername+" yipeeee!!! that's correct "+ "keep up the good work");
            score = score + 350;
            sum_pos = sum_pos + 1;
            totalscore += score;
            System.out.println("round 1");
            System.out.println("level 1");
            question_count = question_count + 1;
            System.out.println("the total score is "+ totalscore);
            tries++;
        }
        else if(choice == 'B'|| choice == 'b')
        {
            System.out.println(playername+" Beeeeeeeeep!! you are wrong "+ "plz try again");
            score = score -185;
            sumneg = sumneg +1;
            totalscore -= score;
            System.out.println("round 1");
            System.out.println("level 1");
            System.out.println("the total score is "+ totalscore);
            tries++;
        }
        System.out.println("+*+*+*+*+*+*+*+*+*+*+*welcome to round 2+*+*+*+*+*+*+");
        for(i =1; i<=4;i++)
        {
            rand  = 1 + randobj.nextInt(25);
            rand2 = 1 + randobj.nextInt(8);
            correctans = rand - rand2;
            incorrectans = 25 + randobj.nextInt(50);
            System.out.println(playername+" round 2 "+ "level "+ i + " Question "+ i+ " you are kindly ask to match the letter to the correct answer");
            System.out.println(playername+" what is the difference between "+rand+ " - "+ rand2);
            System.out.println("A:"+incorrectans);
            System.out.println("B:"+correctans);
            choice = userinput.next().charAt(0);
        if(choice == 'A' || choice == 'a')
        {
            System.out.println(playername+" awesome!!!! that is correct "+" you are doing great!! "+ " keep up the good work");
            score = score + 350;
            sum_pos = sum_pos + 1;
            question_count = question_count + 1;
            totalscore += score;
            System.out.println("round 2");
            System.out.println("level 5");
            System.out.println("the total score "+ totalscore);
            tries++;
        }
        else if(choice == 'B'|| choice == 'b')
        {
            System.out.println(playername+" bleep!!! you are wrong "+ " come one, try again");
            score = score - 185;
            sumneg = sumneg +1;
            count = count + 1;
            totalscore -= score;
            System.out.println("round 2");
            System.out.println("level 5");
            System.out.println("the total score is "+ totalscore);
            tries++;
        }
            System.out.println("+*+*+*+*+*+*+welcome to round 3+*+*+*+*+*+*+*+");
            rand  = 1 + randobj.nextInt(25);
            rand2 = 2 + randobj.nextInt(7);
            correctans = rand / rand2;
            incorrectans = 25 + randobj.nextInt(50);
            System.out.println(playername+" round 3 "+ "level "+ i + " Question "+ i+ " you are kindly ask to match the letter to the correct answer");
            System.out.println(playername+" what is the difference between "+rand+ " / "+ rand2);
            System.out.println("A:"+correctans);
            System.out.println("B:"+incorrectans);
            choice = userinput.next().charAt(0);
        if(choice == 'A'|| choice == 'a')
        {
            System.out.println(playername+" DITTO!!! correct is right "+ "excellent job!!!");
            score = score + 380;
            sum_pos = sum_pos + 1;
            question_count = question_count + 1;
            System.out.println("round 3");
            System.out.println("");
            totalscore += score;
            System.out.println("the total score is "+ totalscore);
        }
        else if(choice == 'B'|| choice == 'b')
        {
            System.out.println(playername+" DING DONG you are wrong!!!! "+ " this doesnt look good");
            score = score - 185;
            sumneg = sumneg + 1;
            totalscore -= score;
            System.out.println("round 3");
            System.out.println("");
            System.out.println("the total score is " + totalscore);
            tries++;
        }
        }
            here is the output
            A report is submitted at the end of the game
A player only win the game if all 10 question are answered correctly
A player loses the game if the age is entered incorrectly or if the player ran out of the chances given
okay students, I hope that I have made myself very clear
+*+*+*+*+*+*+*+*+welcome to the game 1+*+*+*+*+*+*+*+
Hi what is your name
keiron
keiron your name is very unique, my dearest
keiron how old are you
11
keiron come let's play
keiron round 1, level 1 Question 1 can you match the letter to the correct answer
keiron what is 3 + 6
A:9
B:29
A
keiron yipeeee!!! that's correct keep up the good work
round 1
level 1
the total score is 350
+*+*+*+*+*+*+*+*+*+*+*welcome to round 2+*+*+*+*+*+*+
keiron round 2 level 1 Question 1 you are kindly ask to match the letter to the correct answer
keiron what is the difference between 11 - 4
A:48
B:7
BUILD STOPPED (total time: 26 seconds)
why is it jumping to round 2 after running 1 question from round 1 when it should generate 4 question first before going on to round 2.
the same should be for round 2. it has to generate 4 question before going on to round 3 but it is not doing what it is supposed to.
looking forward to a favourable reply thanks in advance

the sooner that I can get a reply the faster this program i can finished



#2 Unkish

Unkish

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 50 posts

Posted 29 November 2015 - 09:51 AM

It's cause your for loop

for(i = 1; i <=4; i++)//getting the four numbers to be generated
{

contains round 2.. inside it whereas you probably wanted your loop to end before

System.out.println("+*+*+*+*+*+*+*+*+*+*+*welcome to round 2+*+*+*+*+*+*+");

Thus looking shmt. like this:

for(i = 1; i <=4; i++)//getting the four numbers to be generated {
            //get random numbers
            rand  = 1 + randobj.nextInt(25);
            rand2 = 1 + randobj.nextInt(8);
            correctans = rand + rand2;//this is to hold all the correct answer
            incorrectans = 25 + randobj.nextInt(50);//this is to hold all the wrong answer
            System.out.println(playername+" round 1,"+ " level "+ i+ " Question "+i+ " can you match the letter to the correct answer");
            System.out.println(playername+" what is "+rand+ " + "+ rand2);
            System.out.println("A:"+correctans);
            System.out.println("B:"+incorrectans);
            choice = userinput.next().charAt(0);
        if(choice == 'A' || choice == 'a')
        {
            System.out.println(playername+" yipeeee!!! that's correct "+ "keep up the good work");
            score = score + 350;
            sum_pos = sum_pos + 1;
            totalscore += score;
            System.out.println("round 1");
            System.out.println("level 1");
            question_count = question_count + 1;
            System.out.println("the total score is "+ totalscore);
            tries++;
        }
        else if(choice == 'B'|| choice == 'b')
        {
            System.out.println(playername+" Beeeeeeeeep!! you are wrong "+ "plz try again");
            score = score -185;
            sumneg = sumneg +1;
            totalscore -= score;
            System.out.println("round 1");
            System.out.println("level 1");
            System.out.println("the total score is "+ totalscore);
            tries++;
        }
}