What I'm attempting to do is have 2 or three do while loops that each have 10 or so if statements within that contain questions. Each if statement (question) is assigned a number (generated by random num gen) and triggers a different question. I want them to trigger randomly when the program is run- So if you run it once the 3rd question in the list might trigger first and the next time the 7th question might trigger first. A sample do while loop is below:
do {
i++;
//set what variable you want to represent random vars
randomint = randomGenerator.nextInt(10);
System.out.println(randomint);
/*
* need to generate 1 number per do loop (as opposed to 10 each loop which this is doing)
* and make sure that the numbers 1-10 are all hit within the 10 cycles of the do loop
* then will do again for a harder set of questions in the second loop
*/
if(randomint==1) {
System.out.println("What is the capital of PA?");
guess= in.nextLine();
if(answer1a.equals(guess) || answer1b.equals(guess)) {
System.out.println("Correct! Good job!");
score=score+5;
}
/*
* add another for loop that gives 4,3,2,1,0 points based on # of guesses used
*/
else {
do {
System.out.println("Nope, try again!");
guess= in.nextLine();
if (answer1a.equals(guess) || answer1b.equals(guess))
System.out.println("Correct! Good Job!");
}while (!answer1a.equals(guess) && !answer1b.equals(guess));
}
}
} while (i !=10);
So that same "if" statement will be repeated for ==2,==3, etc.. for different questions Obviously the problem here is that every time the do loop repeats I generate a completely new set of 10 random numbers. Is there a way to generate 10 random numbers but it stops after each one and scans through my if statements so it picks one, then continues onto the second value in the random number generator? I want this to ask each individual question (10) and then exit the original do loop as determined by my i++ count.
I did try to search for this but was having trouble finding anything- It might possible be a term tat I havent come across yet. Thanks all