# Thread: even more loop trouble

1. ## even more loop trouble

Now that I'm over my fear of random numbers I'm working on the next exercise in my book.
Code:
```Exercise 5-6:
A lottery entry requires you to choose six different integers in the
range 1 to 49 inclusive. Write a program that generates 5 lottery
entries each time it runs```
It's my understand this exercise wants me to generate a series of 6 random integers from 1-49 five different times. So far, I've been succesful on the first set of 6 numbers - but when my program outputs those to the screen it just hangs there. The logic is as follows: a do while loop initiates the loop with the random number generator... this loop continues until 6 numbers have been found and have been output onto the screen. From here -the program is supposed to execute the if statement - that checks for the 6 lotto numbers, which then increments the do while loops counter. Here is the code:
Code:
```#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main()
{
srand(time(NULL));
int i = 0;
int num = 0;
int a = 0;

do{

while(a <= 5){
num = rand() % 48 + 1; //numbers 1-49
cout <<" "<< num; //outputs 1 lotto digit (should be 6 total)
a++; //increments the variable a to match conditions in the while loop

if(a == 6){
cout << endl;
i++; //increments the first while loop counter
}

}

}while(i <= 5)   ;         //end of while loop

system("PAUSE");
return EXIT_SUCCESS;
}```
The error I made I am completely oblivious too I guess - I can't seem to find the problem.. and I'm sorry I can't - because I feel like I'm wasting you guys' time!

2. Code:
```while(a <= 5){
num = rand() % 48 + 1; //numbers 1-49
cout <<" "<< num; //outputs 1 lotto digit (should be 6 total)
a++; //increments the variable a to match conditions in the while loop

if(a == 6){
cout << endl;
i++; //increments the first while loop counter
}

}```
Testing if a > 5 inside a loop that only runs while a<=5 will never trigger, so it will always be stuck at 1.

You also never reset a, so it will go through 5 times, then repeat the outside loop endlessly, without entering the inside loop.

3. Yikes, what was I thinking?

EDIT: ...and I've just fixed it - thank you for the help!