In addition to OriginalGriffs points I'd like to add:
4. Don't use recursion until you know how it works and understand the repercussions on runtime behaviour. (You call
select()
withtin the function itself recursively)
5. Your array
arr
hasn't been defined properly, if defined this way, the dimensions
must be constants, not variables. (and the compiler will tell you that!) Moreover, you never initialized the dimensions. You either must allocate the array dynamically, or - better - use
std::vector
instead.
6. You are using the variables x and y to access the array, but you never modify these values.
7. Nor do you ever check them for valid values: in several places you're accessing array elements at x-1, y-1, x+1, or y+1, either of which may be outside the bounds of the array.
7.1 talking about that - you have a comparison against
arr[w][h]
which
is outside the bounds - or would be if the variables
w
and
h
were (a) initialized) and (b) known inside the function
select()
(hint: both (a) and (b) are not true!)
8. I don't see any code responsible for enumerating all possible routes. You're supposed to count them. I only see you counting steps (i. e. the length of one route)
9. There's nothing random in the task description. Don't use
rand()
!
10. The task specifically mentions there may be a very high number of routes. Given that, using standard output and input is a bad idea! Use files instead!
Having said all that, I suggest you forget about this particular site for now, and instead learn to program in C/C++ using proper tutorials, e. g.
http://www.cplusplus.com/doc/tutorial/[
^] or
http://www.cprogramming.com/tutorial/c++-tutorial.html[
^]. That should help you avoid most of these issues, and may give you a better idea on how to structure a program.