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(constint hexNumber1[], constint hexNumber2[])
{
int x;
for(int i=0; i<5; i++)
{
x = 5-i-1;
if (hexNumber1[x] > hexNumber2[x])
return 1;
elseif (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".
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.