Results 1 to 4 of 4
  1. #1
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    34
    Rep Power
    0

    Default Math Quiz Program

    Im trying to make a program that quizzes the user on simple one-digit additions. I want to tell the user wether the they got the answer right or wrong but don't quite know how to do that. Would I need to use a boolean? Please help!
    Heres what I have so far

    // variable declarations (and some initializations)
    Scanner keys = new Scanner(System.in);
    Random nums = new Random(); // Step 2.
    int n1 = nums.nextInt(10); // Step 3a.
    int n2 = nums.nextInt(10); // Step 3b.
    // now the program logic ...

    System.out.println(n1 + "+" + n2); // Adds two random numbers together
    System.out.print("Enter answer: "); // Prompt user for answer
    int answer = keys.nextInt(); // User input

    if (?????) { //
    System.out.println("Correct");
    } else {
    System.out.println("Wrong!!!");
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default Re: Math Quiz Program

    If (n1+n2 == answer)?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    34
    Rep Power
    0

    Default Re: Math Quiz Program

    Okay thanks, now how can i make this loop ten times?

  4. #4
    serotonin is offline Member
    Join Date
    Jan 2013
    Location
    england
    Posts
    9
    Rep Power
    0

    Default Re: Math Quiz Program

    Java Code:
    for ( int i=1; i<11; i++ ) {
     \\ place your repetition code here
    }

    the format for loops is :-

    for (initialization; termination; increment) {
    statement(s)
    }
    Last edited by serotonin; 11-25-2013 at 11:14 PM.

Similar Threads

  1. a quiz program
    By tom2zip in forum New To Java
    Replies: 6
    Last Post: 12-15-2011, 03:17 AM
  2. Help with quiz program
    By askinne2 in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 10:49 PM
  3. quiz program using access as database
    By miinnesh in forum AWT / Swing
    Replies: 5
    Last Post: 03-05-2010, 11:30 AM
  4. quiz program using access as database
    By miinnesh in forum JDBC
    Replies: 0
    Last Post: 03-05-2010, 05:54 AM
  5. Math Program
    By stlboi in forum New To Java
    Replies: 8
    Last Post: 04-02-2009, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •