"Control reaches end of non-void function", with used "else return 0"

Viewed 55

This function finds the minimum natural number, where the product of digits is equal to the specified number. I used "else return 0" in the function, but the compiler does not stop warning about "control reaches end of non-void function [-Wreturn-type]". What wrong with it? I want to rewrite the code, but this error makes me worry about my competitions of the language.

int minimal_natural_number(unsigned &n){
    static int q = 0;
    static int power = 0;
    static bool check = 0;
    static bool simple = 0;
    if (check && n > 9){
        int i = 5;
        while (i < 10){
            if (n % i == 0){
                n /= i;
                q = (q * 10) + i;
                ++power;
                break;
            }
            else if (i == 9 && (n % i) != 0){
                simple = 1;
                break;
            }
            ++i;
        }
        if (!simple) minimal_natural_number(n);
        else return -1;
    }
    else if (!check && n > 9){
        for (int i = 2; i < 9; ++i){
            if (n % i == 0){
                n /= i;
                q += i;
                check = 1;
                break;
            }
            else
                simple = 1;
        }
        if (!simple) minimal_natural_number(n);
        else return -1;
    }
    else if (!check && n <= 9)
        return n;
    else if (check && n >= 5 && n <= 9)
        return q * 10 + n;
    else if (check && n < 5)
        return (n * pow(10, power) + q);
    else return 0;
}
0 Answers
Related