//----------------------*-------------------------------------------------------*-----------------------------*
for (int loop_generate = 0; loop_generate < choice.character_amount; loop_generate++) {
random_number = rand () % 50;
if (choice.include_letters) {
//Code for generating letters
}
if (choice.include_chiffres) {
//Code for generating chiffres
}
if (choice.include_characters) {
//Code for generating characters}
}
}
In my program the user can generate random words, they can choose what to include: chiffres, letters, and characters. When my program generates then it first checks what the user has chosen, if he has chosen it, it gets included in the random word (see if statements with choice.include...).
The problem now is, that the user can also select the length of the word, it works perfectly when the user selects all options (letters, chiffres, and characters) but when he only chooses one or two options the word doesn't include the amount of selected length in the word.
>So I need to check with a while loop or something if the words does include the selected length it's okay, else we need to keep repeating the process until it does include the right length. If it isn't clear, and you're a real C++ Guru feel free to say so I can PM you the full code.
1) Code you posted does not have any problem with it.
2) It does not even hint on way you generate your word so we could guess wha the problem could be. From what you posted it could be anything from childish mistakes which generally work only by luck to complex mistake you need deep understanding of C++ to find.
Those 3 ifs looks sketchy.
I would suggest making an alphabed and include characters based on choices, then have single code to generate word from all characters included in alphabet. Example:
1 2 3 4 5 6 7 8 9 10 11 12
staticconst std::string letters = "abcd...yz";
staticconst std::string chiffres = "1234567890";
staticconst std::string characters = "!@#$...";
/*...*/
std::string alphabet;
if (choice.include_letters) alphabet += letters;
if (choice.include_chiffres) alphabet += chiffres;
if (choice.include_characters) alphabet += characters;
//for(...
//Code for generating symbols