0

I am trying to print out the max price that is found in the array of structs in the function but it keeps giving me zero and not the max number in the array of structs.

  • In `find_company` your `i` variable equals to `4` after the first loop. You should probably assign it to `0` before starting the second loop – E. Shcherbo Mar 03 '22 at 03:45
  • I just made that change and it is still giving me that the highest price is 0 –  Mar 03 '22 at 03:49
  • `find_company` will never make it to `i==1`, since it always returns something during the `i==0` block. – aschepler Mar 03 '22 at 04:29

1 Answers1

1

you return wrong way so loop can't run, with your loop like that, your function will return 1 if first element in array true, otherwise false, and code for maxprice don't run, your code should be like this

    int  ret = -1;
    for (...) {
        if (...) {
            ret = 1;
            break;
        }
    }
    *maxprice = ...;
    for (...) {
        ...
    }
    return ret;
Nguyen Duc
  • 102
  • 4