Unable to return value from while loop/Issue with array

I need to find the amount of digits that make up a user inputted value. I then need to use that number to declare an appropriate size array. (Not allowed to use strings)
First issue - I'm uncertain how to return the result that I need, if "return result" is outside the loop it is not declared in scope and if it's in the loop, the return ends the loop prematurely.
Second issue - if you cannot declare an array using a variable, how am I supposed to declare the array using the result that I get from this function?(Once it's fixed). I only posted the code relevant to what I need help with. Thanks for your time.

1
2
3
4
5
6
7
8
9
10
    int getDigit(int num); //This function finds how many digits are in num.
    {
    	int x = num;
        while(x > 0)
        {
	    x = x/10;
            int result++;
        }
        return result;
    }
1
2
3
4
5
6
7
8
9
10
11
    int getDigit(int num) //This function finds how many digits are in num.
    {
    	int x = num;
    	int result=0;
        while(x > 0)
        {
	    x = x/10;
            result++;
        }
        return result;
    }
Topic archived. No new replies allowed.