Function to find the middle value of three inputted numbers

I have an assignment that asks me to create program that asks the user for three numbers and I have to send it to a function that finds the middle number of the three.
Here's what I have so far
If anyone can tell me what I'm doing wrong that would be greatly 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
  #include <iostream>

using namespace std;

int middle(int x, int y, int z){

	if(x<y && z>y || z<y && x>y ){
        middle= y;

	}
    return y;

	if(y<x && y>z || y<a && z>x)
    {
        middle=x;

    }
    return x;
    if(y<z && x>z || x<z && y>z){
        middle=z;
    }
    return z;

	return ;
}






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;




	return 0;
}
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
#include <iostream>
using namespace std;

/*
int middle(int x, int y, int z){


	if(x<y && z>y || z<y && x>y ){  //logic is good not but not beautiful
        middle= y;  //middle is a function not a variable and does does have any assigmnent
                    //same for line 16 and 21
	}
    return y;   //why are u assigning y to middle and then return y instead.

	if(y<x && y>z || y<a && z>x){    //dont know where "a" is coming from
            middle=x;
    }
    return x;
    if(y<z && x>z || x<z && y>z){
        middle=z;
    }
    return z; //all your return x,y,z are not part of any if scope, hence only the first return will work
	return ;  //asides the point above, your function returns integer, hence you must return an integer value.
}
*/

int middle(int x , int y, int z)
{
    if(x<=y && y<= z)
        return y;
    if(y<=x && x<=z)
        return x;
    if(x<=z && z<=y)
        return z;
}
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:  ";
	cin>>c;

	md=middle(a,b,c);
	cout << endl<<"middle is "<<md <<endl;
	return 0;
}
Oh I see what I was doing wrong...
Thanks for your help! It's greatly appreciated.
Topic archived. No new replies allowed.