Writing a separate prompt function is a good idea, because you can't be sure that the user will type 'y' or 'n'.

Although you could check for this in the main program, sometimes it's easier to separate details like this from the main function.