Hi guys, I'm writing a weasel program and needed a random character generator, I used a random number generator to give an ascii code for each character, and made a sequence of them, then I realized I needed to include the "space" symbol, but upon inclusion of the new code the compiler tells me my character variable c ins't declared in this scope. Before code:
string genstring (){
string generated_string;
string stringsize=inputsentance()
for (int k=0; k<sentance.size(); k++){
int n = rand() % 25;
char c = char(n+65);
string s;
s=s+c;
generated_string.append(s);
s.clear();
}
return generated_string;
}
And after code:
string genstring (){
string generated_string;
string stringsize=inputsentance();
for (int k=0; k<stringsize.size(); k++){
srand(time(0));
int n = rand() % 26;
if (n==26)
{char c = char(32);}
else
{char c = char(n+65);}
string s;
s=s+c;
generated_string.append(s);
s.clear();
}
return generted_string;
}
I don't see how the c variable is any different in both.