Segmentation Fault

I have a Forest array of Tree objects. The array is 21 by 21, but the outside must be predefined with no trees. I am trying to write a member function that will create a random lightning strike to start a fire. I am getting a segmentation fault error from the compiler, but I don't see what is causing it.

Here is the code for the member function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void forest::lightning(double lightProb)
{
  int g, h, s=0;
  double rannum;
  
  while(s!=1){
  
    rannum=static_cast<double>(rand())/RAND_MAX;
    g=(rand()%20)+1;
    h=(rand()%20)+1;

cout<<g<<","<<h<<endl;

     if( (grid[g][h].getStatus()==1) && (rannum<lightProb)){
        grid[g][h].setStatus(burning);
        s=1;
     }
  }
}


Here is the function call in the driver:

1
2
3
4
cout<<"Enter lightning probability: "<<endl;
cin>>lprob;

b.lightning(lprob);

Nevermind, I found the error. It isn't in that code, but code used later.
Topic archived. No new replies allowed.