Question about returning values from other functions

I have converted two base 10 numbers into base 16 and stored them into an an array. I am to return -1 if one is greater than the other, return 1 if one is less than the other, and return 0 if both are equal. I have set up a loop to check each array and here is a snippet of my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int compare(const int hexNumber1[], const int hexNumber2[])
{
	int x;

	for(int i=0; i<5; i++)
	{
		x = 5-i-1;

		if (hexNumber1[x] > hexNumber2[x])
			return 1;
		else if (hexNumber1[x] < hexNumber2[x])
			return -1;
	}

	if (hexNumber1[x] == hexNumber2[x])
			return 0;
}


The thing is that when I compile I get an error that says:" 'compare' : not all control paths return a value".

What deoes this mean and how do I fix it?
Consider an example:
1
2
3
int function(int p){
    if(p > 0) return 5;
}

Now when p < 0, function wont return anything, which is a problem.
in your code, if number1 < number2, -1 is returned, if n1 > n2, 1 is returned. It should be safe to assume that if no value is returned yet, n1==n2. So you can remove line 15.
Thank you, removing line 15 made the program work.
Topic archived. No new replies allowed.