Exercise: Write a program that takes a width and a height and dynamically generates a maze with the
given width and height. The maze must always have a valid path through it (how can you ensure
this?) Print the maze to the screen once it’s been generated.
Hey, this looks like an interesting problem! I don't know what your limitations are or how your maze is supposed to look, but I banged out an implementation to see how a first pass at it might look. I'll start you off with a few hints to see if it turns into more code than what you've posted here.
First, I treated my maze like a series of floors in a building. Since presumably you're printing to a console, you'll be building these floors top down instead of bottom up. There are three different types of things in my building, a floor (which I represent with an underscore '_'), a wall (which I represent with a pipe character '|'), and a trapdoor (which I represent with a space ' '). So at any point on any floor, either you have a floor, a wall, or a trapdoor.
So the way I guarantee that there is a solution is, on every floor there is at least one trapdoor. Then, when I go to the next floor, I pick another place for there to be a trapdoor and make sure not to put any walls between the new trapdoor and the one on the floor above it. That way, there is always at least one way to get from the current floor to the next floor, and eventually to the bottom.