Originally Posted by
fry8
I tried using int min (int x, int y, int z) and it said I didn't need to declare/cast anything so it's not that, but I can't figure out why it isn't working.
What is "it"? Some automated checker that verifies your code is correct? Or just the compiler?
I just compiled your code, and it worked fine (with the modifications I mentioned). But I am not sure if this actually fits with what you're supposed to do with your assignment. If you have initialised global variables x,y,z,min already then the function min() shouldn't take any arguments (just use the globals directly).
Here's what I have:
Code:
int min (int x , int y , int z ) {
int min = x ;
if(x < y && x < z)
{
min = x;
return min;
}
if((y < x) && (y < z)){
min = y;
return min;
}
if((z < x) && (z < y)){
min = z ;
return min;
}
}
int main(void)
{
int mini = min(1,2,3);
mini = min(2,1,3);
mini = min(3,2,1);
}