I am new to programming and Stack Overflow.So I've been building a simple database for my own enjoyment and to practice my knowledge. It registers a user's username, password and assigns a user ID. To a text file and you can also view the user's information.
My main problem is that I want the program to assign the user an ID that is random from say 1-1000 (ex. 1000 being the maximum employees).
This block of code executes when the user registers a new username and password. The program outputs the username, password, and the user ID in this part. I am able to get the program to output a random number for each user made, but I am not able to make it generate numbers with no duplicates.
The program should output a message that if there are no more user IDs available, then the registration process will not complete.
I created a function that prints a bunch of lines to clear the screen, but everything is at the bottom. If there is a different function I can use I would be glad to know!
if (passwordCheck == password) {
const int minEmp = 1, maxEmp = 10;
srand(time(0));
userID = (rand() % (maxEmp - minEmp + 1)) + minEmp;
ofstream outfile (username + ".txt"); //Creates txt file with user name
outfile << "User ID: " << userID << endl << //Outputs info to txt file
"Account Username: "<< username << endl
<< "Account Password: " << password;
outfile.close();
clearScreen(); //My function to add lines to clear the screen
cout << endl << "Your account has been created." << endl
<< endl << "Returning to main menu.";
clearScreen();
mainMenu(); //Function to return back to menu