how to stop a void function

how to stop a void function ???

i remember that using
return;
can stop the void function.

however, at the end of the following function, it prints win but it did't stop
i am reall confused...

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  void gogo(vector<vector<int> > &maze, int p, int q){
	int ways=0, go;
		
	srand(time(NULL));	
	go=rand()%4;
	
	maze[p][q]=3;
	
	
	
	if(maze[p-1][q]==0||maze[p-1][q]>=201){
		ways++;
	}	
	if(maze[p+1][q]==0||maze[p+1][q]>=201){
		ways++;
	} 	
	if(maze[p][q-1]==0||maze[p][q-1]>=201){
		ways++;
	}	
	if(maze[p][q+1]==0||maze[p][q+1]>=201){   
		ways++;
	} 
	
	
	
	
	if(ways>=2){ 
		r=p;
		k=q;
	}
	else if(ways<=1){
		r=r;
		k=k;
	}
						            
	cout<<"ways= "<<ways<<endl;
	cout<<"go= "<<go<<endl;  
	cout<<"p= "<<p<<endl;
	cout<<"q= "<<q<<endl;
	cout<<r<<","<<k<<endl;
	system("pause");		
	////////////////////////////////// 
	if(go==0&&(maze[p-1][q]==0||maze[p-1][q]>=201)){ 
		maze[p-1][q]==3;	  	  
		printrealmaze(maze);
		gogo(maze,p-1,q);    
	}	
	if(go==1&&(maze[p+1][q]==0||maze[p+1][q]>=201)){  
		maze[p+1][q]=3; 		       
		printrealmaze(maze);
		gogo(maze,p+1,q);    
	}	
	if(go==2&&(maze[p][q+1]==0||maze[p][q+1]>=201)){ 
		maze[p][q+1]=3;  		      
		printrealmaze(maze);
		gogo(maze,p,q+1);    			
	}	
	if(go==3&&(maze[p][q-1]==0||maze[p][q-1]>=201)){ 
		maze[p][q-1]=3;		      
		printrealmaze(maze);
		gogo(maze,p,q-1);    
	}
	////////////////////////////////  
	if(go==0&&maze[p-1][q]!=0&&maze[p-1][q]<200&&ways!=0){
		gogo(maze,p,q);
	}	
	else if(go==1&&maze[p+1][q]!=0&&maze[p+1][q]<200&&ways!=0){
		gogo(maze,p,q);
	}	
	else if(go==2&&maze[p][q+1]!=0&&maze[p][q+1]<200&&ways!=0){
		gogo(maze,p,q);			
	}
	else if(go==3&&maze[p][q-1]!=0&&maze[p][q-1]<200&&ways!=0){
		gogo(maze,p,q);
	}

	
	///////////////////////////////////
	else if(ways==0&&(p!=-3+maze[0].size()&&q!=-3+maze.size())){
	    p=r;
	    q=k;
	    
		gogo(maze,p,q);
	}
	cout<<"win"<<endl;
	
	return;

}
What do you mean by 'stop' a function?
to jump out of it.

i expect that it will jump out of this function after print win,
but it didn't jump out of it.

if i write the" return; " at the top of the function , it can jump out of the function.

i have no idea why it happens @@
Last edited on
void function doesn't need any return i think
return 0 to stop the void function :)
Topic archived. No new replies allowed.