It's because when you enter Y or y aren't you also pressing [enter]? You are leaving the [enter] in the buffer for the next input statement. You need to clear your buffer. I leave that exercise for you to search out.
A couple problems, though:
Never call srand() inside your program. Call itonly once at the beginning of main() . You are seeding the random generator, not growing a forest of generators :icon_wink:
If you check if 'y' or 'Y' is entered, what are the possible values for theelse condition? Is there really a need to test if the value is not 'y' or 'Y'?
Why are you calling play_game() then you have 2 WHILE loops to catch the result? Call the play_game() function only inside one single WHILE loop and use yourYES choice to exit that loop. Your program will be much smaller and easier to follow. And you won't need all that IF nonsense at the end of the loop since the WHILE acts as an IF anyway.