Password Generator | Sololearn: Learn to code for FREE!


Password Generator

Hello gang, I’m trying to make a random password generator. My syntax kinda explains my thought process: Create a huge string with all the characters needed, make a loop which randomly selects characters from it until it has reached 8 characters. But of course it doesn’t work the way I want it to. Any help would be appreciated.

1/19/2019 10:10:12 PM


8 Answers

New Answer


There are several errors in the code. You don't need to prototype main() inside it. And since you need to output "Your PW:" only once, put it outside of the loop. Here's a fixed one. Try to compare this with your code to understand it better.


This is what you should do in line 21: std::cout<< str[rand()%str.length()]; srand() is used for seeding the rand() function. You should use rand() instead of srand(). rand() doesn't accept parameters.


Thank you again!


Wow thank you!


Fixed it, but there is still one tiny error in the switch statement. Mind taking a quick look?


I guess you want something like this


very efficient, I like the version!

+1 Click the above link and get your require code☺