Hello,

Here are the steps I followed:

1. Generate Lotto numbers 1 - 20.

2. User makes a bet.

3. Swap Lotto numbers (swap left-right).

4. Computer picks (3) random numbers from Lotto and stores them in a separate array.

5. Bubble sort function sorts both user's winning numbers.

6. Compare if Lotto numbers and user's numbers coincide. If yes, show a number of iteration it took to get it done. If not, loop again.

Used the MS Visual Studio Community 2015.

When increased a total number from 20 to 40 and winning numbers up to 6, I had to add more to this line:Code:# include <stdio.h> # include <stdlib.h> # include <time.h> # include <windows.h> #pragma warning(disable:4996) # define NUMS 20 # define BET 3 int main() { srand(unsigned(time(NULL))); int iLotto[NUMS] = { 0, }; int iBet[BET] = { 0, }; int win_nums[BET] = { 0, }; /* 1. Generate Lotto numbers (1 - 20) */ for (int i = 0; i < NUMS; i++) { iLotto[i] = i + 1; printf("%d ", iLotto[i]); } /* 2. User makes a bet*/ printf("\nEnter (%d) numbers:\n", BET); for (int i = 0; i < BET; i++) { scanf("%d", &iBet[i]); } int temp = 0; int counter = 0; while(true) // while loop begins { /* 3. Swap Lotto numbers (swap left-right) */ for (int i = 0; i < NUMS; i++) { int left = rand() % NUMS; int right = rand() % NUMS; temp = iLotto[left]; iLotto[left] = iLotto[right]; iLotto[right] = temp; } /* show swapped lotto numbers */ for (int i = 0; i < NUMS; i++) { printf("%d ", iLotto[i]); } /* 4. Computer picks (3) random numbers from Lotto and stores them in a separate array */ for (int i = 0; i < BET; i++) { win_nums[i] = iLotto[i]; } putchar('\n'); /* 5. Bubble sort function sorts both user's winning numbers */ int swapped1; int temp1 = 0; while (1) { swapped1 = 0; for (int i = 0; i < BET - 1; i++) { if (iBet[i] > iBet[i + 1]) { temp1 = iBet[i]; iBet[i] = iBet[i + 1]; iBet[i + 1] = temp1; swapped1 = 1; } } if (swapped1 == 0) { break; } } /* end of bubble sort for a user */ int swapped2; int temp2; while (1) { swapped2 = 0; for (int i = 0; i < BET - 1; i++) { if (win_nums[i] > win_nums[i + 1]) { temp2 = win_nums[i]; win_nums[i] = win_nums[i + 1]; win_nums[i + 1] = temp2; swapped2 = 1; } } if (swapped2 == 0) { break; } } /*end of bubble sort for winning numbers*/ /* 6. Compare if winning numbers and user's numbers coincide. */ for (int i = 0; i < BET; i++) { for (int k = 0; k < BET; k++) { if (win_nums[i] == iBet[k]) { counter++; break; } else continue; } } /* If yes => show a number of iteration it took to get it done. If not => loop again.*/ if ((win_nums[0] == iBet[0]) && (win_nums[1] == iBet[1]) && (win_nums[2] == iBet[2])) { printf("Winning numbers: "); for (int i = 0; i < BET; i++) { printf("%d ", win_nums[i]); } printf("\nYour pick: "); for (int i = 0; i < BET; i++) { printf("%d ", iBet[i]); } printf("\ncounter: %d\n", counter); break; } } system("pause"); return 0; }

So it became:Code:if ((win_nums[0] == iBet[0]) && (win_nums[1] == iBet[1]) && (win_nums[2] == iBet[2]))

As a result it keeps on looping non stop. While it takes only 300--700 iterations with 20 numbers and 3 winning numbers to find a winner. Any idea on what's wrong?Code:if ((win_nums[0] == iBet[0]) && (win_nums[1] == iBet[1]) && (win_nums[2] == iBet[2]) && (win_nums[3] == iBet[3]) && (win_nums[4] == iBet[4]) && (win_nums[5] == iBet[5]))