Middle number debug

I wrote this program awhile back and it seemed to work fine. It's supposed to ask the user to enter three numbers and then it outputs the middle number. I realized when I enter 2,1, and 3 in that order it outputs some random large number. (It might be 3, 1 ,2). Can someone tell me where my error is? I can't seem to find it.
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
int middle(int x, int y, int z){
	cout << x << " " << y << " " << z << endl;
	if ((x<=y  && z>=y) || (z<=y && x>=y)) {
		cout << "case 1" << endl;
		return y;
	}
	if ((z>=x && y>=z) || (z>=y && x>=z)) {
		cout << "case 2" << endl;
		return z;
	}
	if ((y>=x && z<=y) || (y>=z && z<=x)) {
		cout << "case 3" << endl;
		return x;
	}
	
	return -1;
}
	
	
	
	
	
	
int main()
{	
	int a;
	int b;
	int c;
	int md;
		
		
	cout << "Please enter a number: ";
	cin>>a;
	cout <<	"Enter another number";
	cin>>b;	
	cout << "Enter one more"<<endl;
	cin>>c;	
				
	md=middle(a,b,c);	
								
	cout << md <<endl;	
			
			
			
			

}
	
Topic archived. No new replies allowed.