getting information out of a for loop

I'm writing a code for a biological simulation. how its working is pretty self explanatory and there are no issues there. However what I need to do is move/save the variable p so that I can use it outside that for loop to start the next part. Any suggestions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  using namespace std; 







int main(){

double r, probred,e,z,c,q;
int countr,countb,countz,red,blue,p;
red= 1;
blue= -1;
countr=0;
countb=0;
countz = 0;

srand(time(NULL));

	
		for (int a=0; a<100; a++){
			
			
			probred = 0.01;
			r =  ((double) rand()/(RAND_MAX+1));
			e =  ((double) rand()/(RAND_MAX+1));
			q = exp(-e);
			p = a;
				if (probred > r && r < q) {
					
						z=red;
						countr = countr+1;
					
				}//closes if statement
				
				else 
				z=0;
				countz = countz+1;
				
				cout << p << " , " << r << " , " << z << "  ,  " << e << "  ,  " << q <<  "  ,  " << countr << "  ,  " << countz << endl;
		
		if (countr == 1) {
			cout <<" nucleation" << endl;
			return p;
			break;
	}//closes if statement
	}//closes for loop
	}//closes main	    
Please explain line 45 and its effect on line 46.
Topic archived. No new replies allowed.