c++ if statement will not end

I am fairly new to c++ and am not sure if i am explaining this correctly.

I have a piece of code( a function) that does not end when running the whole program.

The purpose of the function is to first generate a random number from 0 to 1. Next if that random number is greater than 0.6, it goes into another function. That function virus_death works perfectly. If the random number is less than 0.6 then it will make the virus point push back into a vector called reached. It will also write the point to a file. However, the statement never stops.

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
void replication(vector<Virus>& virus,int a,int b,double& times,int& iv,ofstream& data_file, int p,vector<Direction>& direction_v,vector<Virus>&replicate, int step)
{
	
	//cout<<"Replication: \t"<<a<<"\t"<<b<<endl;
	//data_file<<"Replication: \t"<<a<<"\t"<<b<<endl;
	
	point R,P;
	
	double replicates  = ((double) rand() / (RAND_MAX));
	//how long the virus takes to reach the necleus
	
	if( replicates>0.6)
	{
		cout<<"No Replication "<<endl;
		virus_death(times, iv, virus,a,b,data_file,p,direction_v, step);
	}
	else if( replicates<=0.6)
	{
		cout<<"Replication"<<endl;
		
		ofstream tom;
		tom.open("Timing_nuc.dat");
	
		
		cout<<"Points"<<endl;
		R.x = virus[p].getx();
		R.y = virus[p].gety();
		R.t = virus[p].gett();
		
		cout<<"Write to File"<<endl;
		tom<<p+1<<"\t"<<R.x<<"\t"<<R.y<<"\t"<<R.t<<"\n";
		
		cout<<"New Points"<<endl;
		P.x = a;
		P.y = b;
		P.t = 0;
		cout<<P.x<<"\t"<<P.y<<"\t"<<P.t<<"\n";
		
		
		replicate.push_back(P);
		int aspa = replicate.size();
		cout<<"Replication Size:"<<aspa<<endl;
	}	
}


the function that calls replication is:

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
void location_of_virus(vector<Virus>&virus,double& times,int& iv,ofstream& data_file,vector<Direction>& direction_v,vector<Virus>&virus_engulf,circle&cell_c,circle&nuclei_c, vector<Virus>&replicate, int step)
{
	int a;
	int b;
	
	//int nc,cc,cmc,nci;
	float dis_c, dis_n;
	
	int virus_size= virus.size();
	//type = "virus";
	for(int i =0; i<virus_size; i++)
	{
		a = virus[i].getx();
		b = virus[i].gety();
		
		//to check where the virus is in location to the environment
		dis_c = cell_c.distance(a,b);
		dis_n = nuclei_c.distance(a,b);
		
		if(dis_n < 5)
		{
			location =" Inside Nucleus";
			cout<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<endl;
			data_file<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<"\n";
			replication(virus,a,b,times,iv,data_file,i,direction_v,replicate,step);
		}	
		else if(dis_n ==5)
		{
			location = "Nucleus";
			cout<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<endl;
			data_file<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<"\n";
			nucleus(virus,a,b,times,iv,data_file,i,direction_v,step);
			
		}
		else if(dis_c <25 && dis_n>5)
		{
			location = "Cytoplasm";
			cout<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<endl;
			data_file<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<"\n";
			cytoplasm(virus,a,b,times,iv,data_file,p,direction_v,step);
		}
		else if(dis_c ==25)
		{
			location = "Cell Membrane";
			cout<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<endl;
			data_file<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<"\n";
			endocytosis(virus,a,b,times,iv, data_file,i,direction_v,virus_engulf,cell_c,nuclei_c);
		}
		else if (((a ==0 || a == 50 || a>0 || a<50)&& (b ==0 || b == 50 || b>0 || b<50)) && dis_c>15)
		{
			location ="Extracellular Matrix";
			cout<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<endl;
			data_file<<i+1<<"\t"<<virus[i]<<"\t"<<direction_v[i]<<"\t"<<location<<"\n";
		}
		else
		{
			location ="Left the System";
			cout<<i+1<<"\t"<<virus[i]<<"\t"<<location<<endl;
			data_file<<i+1<<"\t"<<virus[i]<<"\t"<<location<<"\n";
			
		}
	}
}

the statement keeps repeating, is there a way to end it?!?!?
Last edited on
Post the function that calls replication().
I added it to the original problem
Oh, boy.
Um... I don't know. Could it be that you have an indirect recursive loop between replication() and virus_death()? That is, replication() calls virus_death() then some stuff happens and then location_of_virus() somehow gets called before virus_death() returns.
i tried commenting out the virus_death but it did not work,

location_of_virus does not get called before virus_death because location_of_virus is called after every iteration
Sorry, I'll need to see the entire code. I can't see anything that would obviously create an infinite loop.
i sent you the files!
Topic archived. No new replies allowed.