taking information out of a for loop

Hello. I am trying to write a code that will assign a number to a "box" in a 10x10 grid. If it has assigned a 1 I want it to save that and skip over it next time. If it is assigned a 0 I want it run back through and try again. So far I have a code that will run through until it has assigned 100 1s. Not quite what I need to do but maybe this will work with modification? Any help will be appreciated.
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using namespace std; 



int main(){



int v,box[100],aman[100],z,red,blue,counter,p;
double r,e,q,b,probred;
red=1;
blue=-1;
counter=0;





	while (counter < 101){
		for (int a=1; a<101; a++){
			z=0;
			box[a] = a;
			aman[a] = a*z;
			cout << box[a] << "," << aman[a]<<endl;
			Sleep(1000);
			
			
			if (aman[a] == 0){
			cout << box[a] << aman[a]<<endl;
			Sleep(1000);
		
																//	  b = ((double) rand()/(RAND_MAX+1));
																//	  b= exp(-b)*1000;
																//	  Sleep(b);
			probred = 0.01;
			r =  ((double) rand()/(RAND_MAX+1));
			e =  ((double) rand()/(RAND_MAX+1));
			q = exp(-e);
				if (probred > r && r < q) {
					
						z=red;
						counter=counter+1;
						aman[a] = box[a];
					
				}//closes if statement
				else if ( r < q){
					z=blue;
					aman[a] = a*-1;
					counter=counter+1;
					
				}//closes if statement
				
				else 
				z=0;
				aman[a] = a*z;
			}//closes if statement
			
			
		
		
		
			cout << "box is: " << box[a] <<"," <<"     binding is:  " << aman[a] << "," <<"    counter is:  "<< counter <<  endl;
			Sleep(2000);
			if(counter == 100){
			break;
			}//closes if statement
		
				
		
}//closes for loop*/
}//closes while loop

}//closes main

assign a number to a "box" in a 10x10 grid.

Please, explain.
For example box[3][6] may be assigned to =1 and box[3][5] may be assigned to =-1. Then depending on it's assignment it may have to reassign until it's a 1 or if it's already a 1 it shouldn't be touched.Is this improper logic? I am pretty new to programming and thought it would be a good approach.
Ok. Why all the elements are not set to 1 immediately? There must be some purpose for the gradual accumulation. What is it?
Topic archived. No new replies allowed.