Okay, I am going to assume that the grid actually looks like this:
(7,7) o
|
(6,6) o---o
| |
(5,5) o---o---o
| | |
(4,4) o---o---o---o
| | | |
(3,3) o---o---o---o---o
| | | | |
(2,2) o---o---o---o---o---o
| | | | | |
(1,1) o---o---o---o---o---o---o
| | | | | | |
(0,0) o---o---o---o---o---o---o---o |
Part a) should be easy.
For part b), just follow along the path as the user is entering it. Basically, just have two variables for the x and y coordinate (starting at (0,0)), and when the user enters a U, increment the y coordinate, and when the user enters an R, increment the x coordinate.
You would also need an extra
bool
variable or two to keep track of whether the user entered any invalid characters and whether the user went off the grid (see below).
For part c):
-- The first bullet should be easy (just check if the user ever enters anything other than a u, U, r, or R).
-- For the second bullet, if at any point the x coordinate exceeds n or the y coordinate exceeds the x coordinate, then the path goes outside of the grid.
-- The third bullet should be easy if you kept track of the x and y coordinates.
Just check if x and y are both n at the end.