NEED HELP ASAP :: Battelship program

I need help understanding what is going wrong with this program.
I am attempting to create a Battleship c++ program for a class project, which I've been halfway successful so far...

It's a fairly simple program but I can't seem to find where I went wrong; The output will always get up to the point where it asks the user to enter the X & Y coordinates to hit the enemy, and will then end up going into an endless loop.

Also the "restart()" module will not work.

Any help is appreciated, Thank you.






Code:
/***************************************************************************************************************************
This program will simulate a game of Battleship with 10 1x1 boats on a 10x10 grid. *
The program will generate 10 random coordinates(10 numbers for x coordinate and 10 numbers for y coordinate) for the user * *
and the for the opponent. The program will then ask the user to input one x coordinate and one y coordinate, *
which will trigger to program to decide if the user's input matches with any of the opponent's coordinates. *
Then the program will select two random numbers, which will trigger the program to decide *
if those number mathc the user's coordinates. If any inputed coordinates match to the other's *
coordinates that will result a "HIT" for the one who gave the input, which will give *
that person 1 point. If the inputed coordinate IS NOT a match to the other's coordinate, then *
it will result in a "MISS". First person to 10 points wins. *
****************************************************************************************************************************/

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

void goodGuy();
void badGuy();
void rules();
void gameplay(int [], int [], int [], int[]);
void restart();


int main()
{
string endAnswer = "y";
string startAnswer = "n";

int userX[10]; // User's X-axis coordinates.
int userY[10]; // User's Y-axis coordinates.
int enemyX[10]; // Opponent's X-axis coordinates.
int enemyY[10]; // Opponent's Y-axis coordinates.
int counter;
const int userMini = 1; // User's random number minimum value.
const int userMax = 10; // User's random number maximum value.
int i;
int count;
const int enemyMini = 1; // Computer's random number minimum value.
const int enemyMax = 10; // Computer's random number maximum value.
int j;


while (endAnswer == "y")
{
int validate = 0;
endAnswer = "z";
while (startAnswer != "y")
{
cout << "Hello Captain!\n";
cout << "Are you ready to play?\n";
cout << "Please enter 'y' for yes OR 'n' for no: ";
cin >> startAnswer;
cout << endl;
}
goodGuy();

for (counter = 1; counter <= 10; counter++)
{
i = counter - 1;

userX[i] = (rand() % (userMax - userMini + 1)) + userMini; // Randomizing for the user's coordinates.
userY[i] = (rand() % (userMax - userMini + 1)) + userMini;

}
cout << endl;
cout << "Your boats are set! \n";
system("PAUSE");

cout << endl;





badGuy();
system("PAUSE");
for (count = 1; count <= 10; count++)
{
j = count - 1;

enemyX[j] = (rand() % (enemyMax - enemyMini + 1)) + enemyMini; // Randomizing for the opponent's coordinates.
enemyY[j] = (rand() % (enemyMax - enemyMini + 1)) + enemyMini;


}

cout << endl;
cout << "The enemy's boats are set!\n";
system("PAUSE");
cout << endl;




cout << endl;
cout << "The game will now begin!\n";
cout << endl;


gameplay( userX, userY, enemyX, enemyY);

while (validate == 0)
{
cout << "Would you like to restart?\n";
cout << "Please enter 'y' for yes OR 'n' for no: ";
cin >> endAnswer;
if (endAnswer != "y" && endAnswer != "n")
{
validate = 0;
cout << "Invaild input. Try again.\n";

}
else
{
validate = 1;

}
}

if (endAnswer == "n")
{
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Thanks for playing!" << endl;
restart();
}
}





return 0;
}

/****************************************************************
This module will display when the user's boats are being set. *
*****************************************************************/
void goodGuy()
{
cout << "Your boats are being set!\n";
rules();
cout << endl;

}

/**************************************************************************************
This module will display when the opponent's (AKA the computer) boats are being set. *
***************************************************************************************/
void badGuy()
{
cout << "The enemy's boats are being set!\n";
cout << "GET READY CAPTAIN!!";
cout << endl;
}

/*******************************************************************************
This module will display the rules of the game as the "boats" are being set. *
********************************************************************************/
void rules()
{
cout << endl;
cout << "***RULES: \n";
cout << "The rules of the game are simple; You will take turns against the computer to defeat thier armada of BATTLESHIPS!\n";
cout << " The program will ask you to enter one number for the X-axis and one number for the Y-axis, each number MUST BE between 1 and 10.\n";
cout << "The program will then display to you if what you entered was a hit or a miss. There are a total of TEN targets, destroy all ten YOU WIN.\n";
cout << "The enemy will go first.\n";
cout << endl;
cout << "GOD SPEED, and GOOD LUCK Captain!\n";
cout << endl;
system("PAUSE");


}

Code (part 2):
/********************************************************************************
This module is the "behind the scenes" of the majority or the actual gameplay *
*********************************************************************************/
void gameplay(int goodX[], int goodY[], int badX[], int badY[])
{
int loopVar = 0;
const int enemyMini = 1;
const int enemyMax = 10;
int enemyShotX;
int enemyShotY;
int userShotX;
int userShotY;
int goodBoats = 10;
int badBoats = 10;
int goodSearch;
int badSearch;
int valid = 0;



cout << endl;
cout << endl;
cout << "You have: " << goodBoats << " Boats.\n";
cout << "************************" << endl;
cout << "The enemy has: " << badBoats << " Boats.\n";
cout << endl;
cout << endl;
system("PAUSE");
cout << endl;
cout << endl;

while (goodBoats > 0 && badBoats > 0 && goodBoats <= 10 && badBoats <=10)
{
if (loopVar == 0)
{

enemyShotX = (rand() % (enemyMax - enemyMini + 1)) + enemyMini; // Generating the random coordinates for the "shots" from the enemy.
enemyShotY = (rand() % (enemyMax - enemyMini + 1)) + enemyMini;

for (goodSearch = 0; goodSearch < 10; goodSearch++)
{

if (enemyShotX == goodX[goodSearch] && enemyShotY == goodY[goodSearch])
{
cout << "YOU HAVE BEEN HIT!!\n";
goodBoats = goodBoats - 1;
cout << "You now have: " << goodBoats << " Boats left!" << endl;
loopVar = 1; // Tells the program its the user's turn.


}
else
{
cout << "MISS! You still have: " << goodBoats << " Boats left, Captain!" << endl;
loopVar = 1; // Tells the program its the user's turn.
goodSearch = 10;

}


}



}

if (loopVar == 1)
{
while (valid == 0)
{
cout << endl;
cout << "It's your turn Captain!\n";
cout << endl;
cout << "Please enter the X-axis coordinate you would like to fire at: ";
cin >> userShotX;
cout << endl;
cout << "Please enter the Y-axis coordinate you would like to fire at: ";
cin >> userShotY;
cout << endl;
if (userShotX < 0 || userShotX > 11 || userShotY < 0 || userShotY > 11)
{
cout << endl;
cout << "****************" << endl;
cout << "INVALID INPUT. PLEASE TRY AGAIN.\n";
cout << "****************" << endl;
valid = 0;

}
else
{
valid = 1;
}

}
for (badSearch = 0; badSearch < 10; badSearch++)
{
if (badSearch != 10)
{
if (userShotX == badX[badSearch] && userShotY == badY[badSearch])
{
cout << "THATS A HIT!!\n";
cout << "GREAT SHOT CAPTAIN!!\n";
badBoats = badBoats - 1;
cout << "The enemy now has: " << badBoats << "Boats left!" << endl;



}

}
else
{
cout << "MISS! The enemy still has: " << badBoats << " Boats left!" << endl;
cout << "You'll hit'em next time captain!";


}


}
loopVar = 0;



}



}
if (goodBoats > badBoats) // Displays final results.
{
cout << endl;
cout << "CONGRATULATIONS CAPTAIN!\n";
cout << "YOU WIN!\n";
cout << endl;
}
else
{
cout << endl;
cout << "YOU LOSE!\n";
cout << "Don't worry Captain, we'll get them next time!\n";
cout << endl;
}


}


/********************************************************************************************
This module just gives the user some on screen space between the last game and the new game.*
*********************************************************************************************/
void restart()
{
system("PAUSE");
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
}
Output (part 1):

Hello Captain!
Are you ready to play?
Please enter 'y' for yes OR 'n' for no: y

Your boats are being set!

***RULES:
The rules of the game are simple; You will take turns against the computer to defeat thier armada of BATTLESHIPS!
The program will ask you to enter one number for the X-axis and one number for the Y-axis, each number MUST BE between 1 and 10.
The program will then display to you if what you entered was a hit or a miss. There are a total of TEN targets, destroy all ten YOU WIN.
The enemy will go first.

GOD SPEED, and GOOD LUCK Captain!

Press any key to continue . . .


Your boats are set!
Press any key to continue . . .

The enemy's boats are being set!
GET READY CAPTAIN!!
Press any key to continue . . .

The enemy's boats are set!
Press any key to continue . . .


The game will now begin!



You have: 10 Boats.
************************
The enemy has: 10 Boats.


Press any key to continue . . .


MISS! You still have: 10 Boats left, Captain!

It's your turn Captain!

Please enter the X-axis coordinate you would like to fire at: 3

Please enter the Y-axis coordinate you would like to fire at: 5

Output(Part 2):


MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
MISS! You still have: 10 Boats left, Captain!
YOU HAVE BEEN HIT!!
You now have: 9 Boats left!
MISS! You still have: 9 Boats left, Captain!

** It will do this process until the user runs out of boats. Which goes on about 1000 more times.

Topic archived. No new replies allowed.