Ok, so I just made this account because I'm super stuck. Basically I need to create a math quiz that takes a users input (1 through 12), have it spit out a question, i.e What is 5 x 12? however if the user enters 5, it must randomly generate a question asking the user his 5x tables. i.e What is 5x3? What is 5x7? and so on and he needs to enter the correct answer, after which it will display correct or incorrect. I am having trouble getting the user input part. So far my code allows for him to enter an answer, get correct or incorrect, but they it goes to a seperate timestable, i.e first question will be 5x4, next will be 9x11. I need 5-10 random questions just using his input * and 1-12 as the timestable. What I am asking is how am I able to enter an input value for what times table the quiz is on?
import java.util.*;
public class MathQuizzer{
public static void main(String[] args)
{
Scanner a = new Scanner(System.in);
int b,right,totalscore,m;
right = 100;
totalscore = 0;
b = 0;
do
{
double numb = Math.round((Math.pow(10, 2) * Math.random()));
double numb1 = Math.round((Math.pow(10, 2) * Math.random()));
double valueFirst;
double valueSecond;
valueFirst = numb % 12;
valueSecond = numb1 % 12; //Highest Number
double answer;
System.out.print("\nMultiply these two numbers together: ");
System.out.print(valueFirst);System.out.print(" * ");System.out.println(valueSecond);
answer = a.nextDouble();
if(answer == (valueFirst * valueSecond))
{
System.out.println("\nCorrect");
right++;
}
else
{
System.out.println("\nIncorrect");
}
b++;
}
while (b < 10 ); //Number of questions to be asked.
totalscore = right - 100;
System.out.println("\nYour total score is: " + totalscore );
}
}