Password Generator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

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. https://code.sololearn.com/ciL83fB4DS45/?ref=app

19th Jan 2019, 10:10 PM
Dawid
Dawid - avatar
8 Answers
+ 4
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. https://code.sololearn.com/cWwsT4DaOM61/?ref=app
20th Jan 2019, 11:32 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 5
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. https://code.sololearn.com/cBJ8H15dLL8k/?ref=app
19th Jan 2019, 11:06 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
Thank you again!
20th Jan 2019, 11:54 AM
Dawid
Dawid - avatar
+ 1
Wow thank you!
20th Jan 2019, 10:14 AM
Dawid
Dawid - avatar
+ 1
Fixed it, but there is still one tiny error in the switch statement. Mind taking a quick look?
20th Jan 2019, 10:48 AM
Dawid
Dawid - avatar
+ 1
I guess you want something like this https://code.sololearn.com/chkalVvSgT6Y/?ref=app
20th Jan 2019, 7:57 PM
Just4f
Just4f - avatar
+ 1
very efficient, I like the version!
20th Jan 2019, 8:28 PM
Dawid
Dawid - avatar
+ 1
https://code.sololearn.com/czvRpK1TEItY/?ref=app Click the above link and get your require code☺
30th May 2019, 5:23 AM
Nouman Bin Sami
Nouman Bin Sami - avatar