#include #include #include #include // For srand() and rand() #include using namespace std; char grid[15][15]; void printGrid() { // print the current grid cout << endl; for (int x=0; x<15; x++) { for (int y=0; y<15; y++) { cout << setw(2) << grid[x][y]; } cout << endl; } cout << endl; } void createGrid() { // create a blank grid for (int x=0; x<15; x++) { for (int y=0; y<15; y++) { grid[x][y] = '_'; } } } void placeShips() { // there is no check for collision of the ships srand (time(NULL)); int x = rand() % 15; int y = rand() % 15; // put a ship with three spaces on the board - vertical grid[x][y] = 'c'; grid[x+1][y] = 'c'; grid[x+2][y] = 'c'; x = rand() % 15; y = rand() % 15; // put a ship with four spaces on the board - horizontal grid[x][y] = 'd'; grid[x][y+1] = 'd'; grid[x][y+2] = 'd'; grid[x][y+3] = 'd'; } int main () { createGrid(); placeShips(); printGrid(); getchar(); return 0; }