I want a random numbered array, I thought this should work But the array still displays duplicates. However if I put cout something instead of continue it prints it.
for (int x = 0; x < i; x++) {
if (arr[x] == num)
continue;
else
arr[i] = num;
}
Note that continue simply jumps to the next iteration of the loop so the loop could be written like this:
1 2 3 4
for (int x = 0; x < i; x++) {
if (arr[x] != num)
arr[i] = num;
}
The loop writes the number to the array if it's equal to any of the previous numbers in the array. It also prevents the first number to be written to the array because when i == 0 it never even enters the loop.
What you could do instead is to check if the value exists in the array by using a loop, and then after the loop you write the number to the array if it didn't already exist. You also need to think about what you should do if the number already exists in the array.