I want to get a different array in every cycle of loop but this code is creating the same array every time in loop. Please help! I tried putting srand() function everywhere, in function, in main(), in loop, everywhere...
(Sorry for bad English :~)
void randArray(int[], int); //getting random numbers in this function
void input(int[], int);
void assendSort(int[], int);
void printArray(int[], int);
bool win(int[], int[], int);
int main()
{
srand(time(NULL)); //srand() here
int lottNumbers[5], pGuess[5];
bool flag = 1;
randArray(lottNumbers, 5); //getting random numbers in this function
assendSort(lottNumbers, 5);
while (flag)
{
input(pGuess, 5);
cout << endl << "Lottry numbers: ";
printArray(lottNumbers, 5);
if (win(lottNumbers, pGuess, 5))
cout << endl << "You win!";
else
cout << endl << "You lose!";
cout << endl << endl << "Do you want to play again?(1 for yes 0 for no): ";
cin >> flag;
}
return 0;
}
void randArray(int a[], int siz) //getting random numbers in this function
{
for (int i = 0; i < siz; i++)
a[i] = rand() % 40 + 1; //getting random numbers here
}
void input(int a[], int siz)
{
cout << "Guess 5 numbers(1 to 40):" << endl;
for (int i = 0; i < siz; i++)
cin >> a[i];
}
void assendSort(int a[], int siz)
{
int minn, minIndex;
for (int i = 0; i<siz; i++)
{
minn = a[i];
minIndex = i;
for (int j = i + 1; j<siz; j++)
{
if (minn>a[j])
{
minn = a[j];
minIndex = j;
}
}
a[minIndex] = a[i];
a[i] = minn;
}
}
bool win(int lott[], int guess[], int siz)
{
for (int i = 0; i < siz; i++)
{
for (int j = 0; j < siz; j++)
{
if (guess[j] == lott[i])
return 1;
}
}
return 0;
}
void printArray(int a[], int siz)
{
for (int i = 0; i < siz; i++)
cout << a[i] << ", ";
}