So basically I have to make an array that allows the user to randomly generate the amount of numbers of their choice, and none of the numbers can be the same. My code generates them normally but still gets repeated numbers and I'm not sure why as I think I prevented it. I'm still fairly new to arrays so this may look really dumb, any help would be appreciated! I've left a lot of side notes to try and break down each section, and at the bottom I'll include what it looks like when it runs.
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
int main()
{
int numberlist[20]; //the array
int count=0,amount=0,value=0;
bool found=false;
srand(time(NULL)); //makes randomizer not the same
cout << "How many numbers to generate?" << endl;
cin>>amount; //gets user input
for(int count=0; count<amount; count++){
value = rand() % 40 + 1; //generates random number from 1-40 until amount is reached
found=false;
if(value==numberlist[count])found=true; //if value is in the array, change found from false to true
if(value!=numberlist[count] && found==false){ //if number is unique and new
numberlist[count]=value; //add number to array
cout << value << endl; //show the value to the screen
}
else if (found==true) {count--;} //if value is in array erase 1 from count
}
return 0;
}
//What it looks like altogether
//How many numbers to generate?
// 9 (<the users input)
//37
//5
//30
//13
//7
//18
//1
//25
//25 (The 25 is the repeating number in this case)