I wrote a similar exercise a few weeks ago, which asks to generate random the coordinate of the shoot and then to give the computer the "intelligence" to find the ship and sink it. I didn't understand your message, you wrote that if the user put in for three times coordinates where there are no ships the program finishes, isn't it? I can't understand very well the problem you gave us