last problem
Feb 25, 2011 at 10:09pm UTC
I have almost everything done but these two modules are interacting incorrectly. What happens is it fills the grid with A random letter. its like it only calls the RandomLetters() once and sticks with that character. what can i do to fix this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
char RandomLetters()
{
srand(unsigned (time(NULL)));
return (rand() % 26 + 'A' );
}
void CompletePuzzle(char grid[][c])
{
char randomchar;
int i, j; //counters
for (i=0;i<r;i++){
for (j=0;j<c;j++){
if (grid[i][j]=='.' ){
randomchar=RandomLetters()
grid[i][j]=randomchar;
}
}
}
return ;
}
Feb 25, 2011 at 10:16pm UTC
Feb 25, 2011 at 10:28pm UTC
ahah i see so i should not make a module for random letters instead just intigrate it into the module that needs them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void CompletePuzzle(char grid[][c])
{
char randomchar;
srand(unsigned (time(NULL)));
int i, j; //counters
for (i=0;i<r;i++){
for (j=0;j<c;j++){
if (grid[i][j]=='.' ){
grid[i][j]=(rand() % 26 + 'A' );
}
}
}
return ;
}
Feb 25, 2011 at 10:32pm UTC
No, srand shouldn't be called in any function besides main if you want to be sure it's called only once
Feb 26, 2011 at 12:35am UTC
i think the define of r & c is missing inside CompletePuzzle() function
Topic archived. No new replies allowed.