I am trying to write a section of a program that generates names of 3 letters. First letter a capitol consonant, a second letter that is a vowel, the third that is a lowercase consonant.
char genFirst(){
char c = (rand()%26)+65;
if (c == 97 || c == 101 || c == 105 || c == 111 || c ==117){
genFirst();
}
return c;
}
char genVowel(){
char c = (rand()%26)+97;
if (c == 97 || c == 101 || c == 105 || c == 111 || c ==117){
return c;
}
genVowel();
}
char genLast(){
char c = (rand()%26)+97;
if (c != 97 || c != 101 || c != 105 || c != 111 || c != 117){
return c;
}
genLast();
}
This code dosnt work.
Why?
Wouldnt the function call inside of itself, in the event that if statement conditions are or are not being met make the function eventually return what I want? Obviously it's not. I want to know why. Any help would be great. Thanks in advance.