writing definition of a function max

Hello, I'm a beginner of C++ and I'm trying to learn how to write a function from turingscraft.com.
So, the problem is: Write the definition of a function max that has three int parameters and returns the largest.
This what I got, but I don't understand what's wrong with my code. Here is my code for the function:
1
2
3
4
5
6
7
8
9
int max(int x, int y, int z)
{
        if(x > y && x > z)
		return x;
	else if(y > x && y > z)
		return y;
	else if(z > x && z > y)
		return z;
}


And the error indicates: You are returning a completely unexpected value. You should only return one of the numbers.

I don't get why this is wrong because when I ran the program, it worked completely fine. So, is there any other way to write this?
Where did the error come from? The site?
Your code looks fine... you could make it a little simpler... however
you aren't checking for equality. So what happens if x = y = z? or any permutation of the aforementioned?
Yea... the error was from the site. I forgot to check for x = y = z. Thanks a lot!
Topic archived. No new replies allowed.