Problem, Vector/Array

Hello, againg, thanks for the help in my other topic, but now, i need again xD.

in this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.

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

int buscarNumOrdenado (int x [MAX]) //MAX is the define 
{
	int num,d, LimiteInferior, LimiteSuperior,mitad;
	d=0;
	LimiteInferior = 0;
	LimiteSuperior = MAX-1;
	
	cout<<"Favor de escribir el numero que desea buscar ->";
	cin>>num;
	
	while(LimiteInferior <= LimiteSuperior){
		
		
		
		mitad = (LimiteSuperior + LimiteInferior)/2;
		
		if (num == x[mitad]){
			d++;
		}
		
		else
		
		if(num >x[mitad])
		LimiteInferior = mitad +1;
		
		else
		
		LimiteSuperior = mitad-1;
	
	
		
	}
	cout<<"El numero "<<num<<" se encontro "<<d<<" veces";
	
	system ("PAUSE");


Last edited on
Suppose that you find the number. This is what would execute
1
2
3
4
while( LimiteInferior <= LimiteSuperior ){
	mitad = (LimiteSuperior + LimiteInferior)/2;
	d++;
}
┬┐see the infinite loop?
Yes, thanks for the help and im sorry for the late response, prob solved
Topic archived. No new replies allowed.