Novice needs help with maths quiz program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TwistedSpanner
    New Member
    • Dec 2006
    • 1

    #1

    Novice needs help with maths quiz program

    Hello all,
    For the record I am a complete java novice.

    I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows

    Random number, Random operator (+ or -) random number.

    I have written the program but cannot make the random operator work. Can anyone help?

    My code.

    a = myRandom.nextIn t(8) +11;//generates random number
    b = myRandom.nextIn t(8) +1;//generates 2nd random number

    if(b<4)//this code sets random operator + or -
    {
    t='-'; // t is the random operator
    }
    else
    {
    t='+';
    }
    System.out.prin t("Question "+p+": "+((a+t+b)+ "= ? "));//prints question to screen

    Thanks
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by TwistedSpanner
    Hello all,
    For the record I am a complete java novice.

    I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows

    Random number, Random operator (+ or -) random number.

    I have written the program but cannot make the random operator work. Can anyone help?

    My code.

    a = myRandom.nextIn t(8) +11;//generates random number
    b = myRandom.nextIn t(8) +1;//generates 2nd random number

    if(b<4)//this code sets random operator + or -
    {
    t='-'; // t is the random operator
    }
    else
    {
    t='+';
    }
    System.out.prin t("Question "+p+": "+((a+t+b)+ "= ? "));//prints question to screen

    Thanks
    TwistedSpanner-

    Here is a tutorial on random numbers in Java, if you think you have everything right, please post your entire program, and any error messsages you are getting, or what the current output is.

    Comment

    Working...