# Thread: Something's wrong with me Quiz logic..

1. ## Something's wrong with my Quiz logic.. [SOLVED]

Code:
```
for(int Non=0; Non<(sizeof(Question)/sizeof(Question[0])); Non++)
{
Iterator2=true;
while(Iterator2)
{
No = random(0,(sizeof(Question)/sizeof(Question[0])-1));
for(int Ni=0; Ni<Non; Ni++)
{
continue;
else
break;
}
Iterator2=false;
}

cout<<endl<<endl;
cout<<"\t";
DelayType(Question[No], 15, false, 11);
cout<<endl;

cout<<"\t\t    ";
DelayType("a)", 250, false, 15);
cout<<"  ";
DelayType(OptionA[No], 50, false, 7);
cout <<endl;

and so on..

///////////////////////// Question Output /////////////////////////

So focus on the

Code:
``` Iterator2=true;
while(Iterator2)
{
No = random(0,(sizeof(Question)/sizeof(Question[0])-1));
for(int Ni=0; Ni<Non; Ni++)
{
continue;
else
break;
}
Iterator2=false;
}```
This is going to make it so that A question that was asked by the program previously would not be asked again. But this is not working! I have been breaking my head on this for hours I just don't get what is wrong.

The "No" variable holds the question number to be outputted, and I have to make sure No does not repeat itself and hence the While Loop, but the while loop does not seem to work as anticipated

because the same question is being printed out..

2. Your while(Iterator2) loop only ever executes once.

The continue restarts the for loop, not the while loop.

It might be easier if you took this approach.
- Randomise the order just once.
- Then simply loop from 0 to n asking the questions.

3. Originally Posted by Salem
Your while(Iterator2) loop only ever executes once.

The continue restarts the for loop, not the while loop.

It might be easier if you took this approach.
- Randomise the order just once.
- Then simply loop from 0 to n asking the questions.
I definitely want to try randomizing the order itself. Thanks.

Anyways for those of you interested, my logic was flawed in itself. However, I used another variable (Eject) and edited the logic, and now the approach would work.
Code:
```    for(int Non=0; Non<(sizeof(Question)/sizeof(Question[0])); Non++)
{
Iterator2=true;
while(Iterator2)
{
No = random(0,(sizeof(Question)/sizeof(Question[0])-1));
for(int Ni=0; Ni<(sizeof(Question)/sizeof(Question[0]))+10; Ni++)
{
Eject=true;
}
if(!(Eject))
Iterator2=false;

Eject=false;

}

cout<<Question[No]<<endl;