I'm now trying to: 1. Generate four number randomly. 2. Store them in array. 3. Make sure the value in array don't duplicate.
Here is my idea: 1. Generate one number each time in for loop (x4 times) 2. After generating number, using inner loop to compare it to the previous array value.
My code:
do
{
for (int i = 0; i < 4; i++)
{
value[i] = rand() % 6 + 1; // Generating value
for (int j = 0; i > j; j++)
{
if (value[i] == value[j])
{
dup = true; break;
}
if (dup == true) break;
}
}
for (int i = 0; i < 4; i++)
{
cout << "value: " << value[i] << " " << endl;
}
} while (dup != true);
I was wondering why same array value will still be generating, as in my code, the loop will be repeating until no more duplicated value is found.