Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help!! need function to ask user if they want and to produce another 10 qs once programs finished

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help!! need function to ask user if they want and to produce another 10 qs once programs finished

    Scanner keyboard = new Scanner(System.in); //given an object scanner and calling it keyboard


    int randomOne=0, randomTwo=0, problems=1; //memory allocation holds first random number second random number and problems which acts as a counter to keep track of the amount of problems

    int realAnswer=0, userAnswer=0, correct=0, inCorrect=0;//memory allocation product hols the right answer user answer holds the user answer correct holds number of correct and incorrect answers
    int choice;

    while (problems <= 10){//produces 10 multiplication problems after 10 user will be asked if they wish to have another 10 or to quit
    System.out.println("Problem"+ problems + ":"); //prints numbers 1-10
    randomOne = generator.nextInt(13);// generates numbers from 1-13
    randomTwo = generator.nextInt(13);//generates numbers from 1-13
    realAnswer = randomOne * randomTwo; //calculates what these two numbers are equal to
    System.out.println(randomOne+ "*" + randomTwo);//asks the user for their guess as to the answer
    userAnswer = keyboard.nextInt();

    if(userAnswer == realAnswer){
    System.out.println("correct! well done! ");
    correct++;//increments the variable correct

    }
    else{
    System.out.println("incorrect.Try again" + randomOne + "*" +randomTwo);
    while(userAnswer != realAnswer)//this while loop makes the user re-answer the question if they get it wrong
    {
    inCorrect++;//increments the variable inCorrect
    System.out.println(randomOne+"*"+randomTwo);
    userAnswer = keyboard.nextInt();
    }
    }
    problems++;//increments the variable Problems
    }
    System.out.println("you got" + correct + "correct!");
    System.out.println("you got" + inCorrect + "incorrect");
    // here want to ask if they wish to continue or to exit and if continues selected they get another 10 qs dont know how









    }

    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: help!! need function to ask user if they want and to produce another 10 qs once programs finished

    Consider
    1) adding [code] [/code] tags around the posted code in your question above so that it is readable and thus understandable, and
    2) adding some text describing just where you're stuck, what you've tried, how it didn't work, etc...

Similar Threads

  1. Using a method to add two classes and produce a third
    By shamman84 in forum Object Oriented Programming
    Replies: 6
    Last Post: February 5th, 2012, 08:18 PM
  2. Replies: 7
    Last Post: November 18th, 2011, 01:47 PM
  3. Improving the code to produce the same program
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 13
    Last Post: April 8th, 2011, 09:41 PM
  4. [SOLVED] Listen to two JRadioButton + ons JButton to produce output
    By voltaire in forum AWT / Java Swing
    Replies: 1
    Last Post: May 12th, 2010, 03:46 PM
  5. Jigloo help to produce a text area which only scrolls down
    By rtumatt in forum AWT / Java Swing
    Replies: 0
    Last Post: February 2nd, 2010, 05:09 PM