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.
#include <iostream>
usingnamespace 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;
}