Complex problem with options

Hello

I've got a small problem.

Pseudo code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	//----------------------*-------------------------------------------------------*-----------------------------*
	

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.

Thanks for reading,
Niely
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
static const std::string letters = "abcd...yz";
static const std::string chiffres = "1234567890";
static const 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 

^Won't that code just print abc...yz and 123.789 at one? Because a string is just one block of code and doesn't separate them?

I'd like to use your way but don't see how to really use it. I've PM'ed you the full code anyway.
Topic archived. No new replies allowed.