We just learned arrays the other day, so I'm a little confused.
Assignment is to create an array of questions, and an array of answers, ask a random question using Math.random, and to compare the user-inputted answer to the answer I have provided. (then do cute congratulations you win stuff at the end, but that's easy).
I've got all of that.. the only part I can't quite figure is out how to not ask the same question twice.
I have a for loop from 1 to 10 (for 10 questions), and I'm putting an integer i equal to random*10.
Example:
and then I'm calling the arrays using questions and and comparing useranswer with answers.
I guess my question is.. how would I go about storing values the values of i that have already been produced by math.random and comparing them with the newly produced math.random integer so I don't ask the same question twice?
..and also checking the values while having still having the for loop run 10 times (rather than wasting a loop dealing with the comparison).
Any tips/guidance would be helpful. Thanks!
Assignment is to create an array of questions, and an array of answers, ask a random question using Math.random, and to compare the user-inputted answer to the answer I have provided. (then do cute congratulations you win stuff at the end, but that's easy).
I've got all of that.. the only part I can't quite figure is out how to not ask the same question twice.
I have a for loop from 1 to 10 (for 10 questions), and I'm putting an integer i equal to random*10.
Example:
Code:
for (int counter = 1; counter <= 10; counter++)
{
int i = (int) (Math.random()* 10);
and then I'm calling the arrays using questions and and comparing useranswer with answers.
I guess my question is.. how would I go about storing values the values of i that have already been produced by math.random and comparing them with the newly produced math.random integer so I don't ask the same question twice?
..and also checking the values while having still having the for loop run 10 times (rather than wasting a loop dealing with the comparison).
Any tips/guidance would be helpful. Thanks!