I'm in the process of designing a battleship game and I need some help of why I'm coming up with a error.

The error is:error C4430: missing type specifier - int assumed. Note: C++ does not support default-int.

Another question is, how would i randomly place the battleships in the battlegrid? Thanks!

//10-9-09
//ask gaspar if i could use a string datatype(A5) for the guess or should
//ask the player to input to separate inputs?

#ifndef BATTLEGRID_H
#define BATTLEGRID_H

#include <iostream>
using std::string;
#include <string>
#include <vector>
#include <algorithm>

const int ROW = 13;		//row
const char COLUMN = 13;	//column;

class BattleGrid
{
public:
	//battleGrid constructor
	BattleGrid(string = "");	//, int = 0 , char = 0
	
	//battleGrid destructor
	~BattleGrid();	
         
         //error C4430: missing type specifier - int assumed. Note: C++ does not support default-int.
	void displayBoard(const vector<string> &);	//grid	
	int markSpot();
	void scatterBattleships();
	//string color[];				//sets the color
	//string draw();				//draws the battlegrids

private:
	string guess;				//players guess
	
	// global constants
//	const char X = 'X';			//represent a hit
	//const char O = 'O';			//represent a miss
	//const char EMPTY = ' ';
	//int xCoordinate;				// letters
	//char yCoordinate;				// numbers
	//int backGround;				//background

	int x[ROW] = {0,1,2,3,4,5,6,7,8,9,10,11,12};		//array x
	char y[COLUMN] = {'a','b','c','d','e','f','g','h','i','j','k','l','m'};		//array y
	
	int grid[ROW][COLUMN] = { {0,0,0,0,0,0,0,0,0,0,0,0,0},	// 2-D grid
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0},
							  {0,0,0,0,0,0,0,0,0,0,0,0,0} }; 
	
};
#endif
//Date started working 10-9-09
#include "BattleGrid.h"
#include <iostream>
#include <cstdlib>	// contains prototypes for functions srand and rand
#include <ctime>	//contains prototype for function time
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

srand(time(0));	//Randomize random number generator using current time.

//BattleGrid constructor
BattleGrid::BattleGrid(string g)	//,int x, char y
{
	guess = g;
	/*xCoordinate = x;
	yCoordinate = y;*/

	//for(int i=0; i<32; i++)		//intialize array x to 0
	//	x[i]=0;

	//for(int i=0; i<32; i++)		//intialize array y to 0
	//	y[i]=0;
}

void displayBoard(const vector<string> &grid)		//display  board
{
	cout << "\n\t" << grid[0][a] << " | " << grid[0][b]<< " | " << grid[0][c] << " | " << grid[0][d]
		  << " | " << grid[0][e] << " | " << grid[0][f]<< " | " << grid[0][g] << " | " << grid[0][h]
		  << " | " << grid[0][i] << " | " << grid[0][j]<< " | " << grid[0][k] << " | " << grid[0][l]
		  << " | " << grid[0][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
    cout << "\n\t" << grid[6][a] << " | " << grid[6][b]<< " | " << grid[6][c] << " | " << grid[6][d]
		 << " | " << grid[6][e] << " | " << grid[6][f]<< " | " << grid[6][g] << " | " << grid[6][h]
		 << " | " << grid[6][i] << " | " << grid[6][j]<< " | " << grid[6][k] << " | " << grid[6][l] 
		 << " | " << grid[6][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
    cout << "\n\t" << grid[2][a] << " | " << grid[2][b]<< " | " << grid[2][c] << " | " << grid[2][d]
		 << " | " << grid[2][e] << " | " << grid[2][f]<< " | " << grid[2][g] << " | " << grid[2][h]
		 << " | " << grid[2][i] << " | " << grid[2][j]<< " | " << grid[2][k] << " | " << grid[2][l] 
		 << " | " << grid[2][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[3][a] << " | " << grid[3][b]<< " | " << grid[3][c] << " | " << grid[3][d]
		 << " | " << grid[3][e] << " | " << grid[3][f]<< " | " << grid[3][g] << " | " << grid[3][h]
		 << " | " << grid[3][i] << " | " << grid[3][j]<< " | " << grid[3][k] << " | " << grid[3][l] 
		 << " | " << grid[3][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[4][a] << " | " << grid[4][b]<< " | " << grid[4][c] << " | " << grid[4][d]
		 << " | " << grid[4][e] << " | " << grid[4][f]<< " | " << grid[4][g] << " | " << grid[4][h]
		 << " | " << grid[4][i] << " | " << grid[4][j]<< " | " << grid[4][k] << " | " << grid[4][l] 
		 << " | " << grid[4][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[5][a] << " | " << grid[5][b]<< " | " << grid[5][c] << " | " << grid[5][d]
		 << " | " << grid[5][e] << " | " << grid[5][f]<< " | " << grid[5][g] << " | " << grid[5][h]
		 << " | " << grid[5][i] << " | " << grid[5][j]<< " | " << grid[5][k] << " | " << grid[5][l] 
		 << " | " << grid[5][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[6][a] << " | " << grid[6][b]<< " | " << grid[6][c] << " | " << grid[6][d]
		 << " | " << grid[6][e] << " | " << grid[6][f]<< " | " << grid[6][g] << " | " << grid[6][h]
		 << " | " << grid[6][i] << " | " << grid[6][j]<< " | " << grid[6][k] << " | " << grid[6][l] 
		 << " | " << grid[6][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[7][a] << " | " << grid[7][b]<< " | " << grid[7][c] << " | " << grid[7][d]
		 << " | " << grid[7][e] << " | " << grid[7][f]<< " | " << grid[7][g] << " | " << grid[7][h]
		 << " | " << grid[7][i] << " | " << grid[7][j]<< " | " << grid[7][k] << " | " << grid[7][l] 
		 << " | " << grid[7][m];
    cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[8][a] << " | " << grid[8][b]<< " | " << grid[8][c] << " | " << grid[8][d]
		 << " | " << grid[8][e] << " | " << grid[8][f]<< " | " << grid[8][g] << " | " << grid[8][h]
		 << " | " << grid[8][i] << " | " << grid[8][j]<< " | " << grid[8][k] << " | " << grid[8][l] 
		 << " | " << grid[8][m];
	cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[9][a] << " | " << grid[9][b]<< " | " << grid[9][c] << " | " << grid[9][d]
		 << " | " << grid[9][e] << " | " << grid[9][f]<< " | " << grid[9][g] << " | " << grid[9][h]
		 << " | " << grid[9][i] << " | " << grid[9][j]<< " | " << grid[9][k] << " | " << grid[9][l] 
		 << " | " << grid[9][m];
	cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[12120][a] << " | " << grid[12120][b]<< " | " << grid[12120][c] << " | " << grid[12120][d]
		 << " | " << grid[12120][e] << " | " << grid[12120][f]<< " | " << grid[12120][g] << " | " << grid[12120][h]
		 << " | " << grid[12120][i] << " | " << grid[12120][j]<< " | " << grid[12120][k] << " | " << grid[12120][l] 
		 << " | " << grid[12120][m];
	cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[1212][a] << " | " << grid[1212][b]<< " | " << grid[1212][c] << " | " << grid[1212][d]
		 << " | " << grid[1212][e] << " | " << grid[1212][f]<< " | " << grid[1212][g] << " | " << grid[1212][h]
		 << " | " << grid[1212][i] << " | " << grid[1212][j]<< " | " << grid[1212][k] << " | " << grid[1212][l] 
		 << " | " << grid[1212][m];
	cout << "\n\t" << "------------------------------------------------------------------------------";
	cout << "\n\t" << grid[12][a] << " | " << grid[12][b]<< " | " << grid[12][c] << " | " << grid[12][d]
		 << " | " << grid[12][e] << " | " << grid[12][f]<< " | " << grid[12][g] << " | " << grid[12][h]
		 << " | " << grid[12][i] << " | " << grid[12][j]<< " | " << grid[12][k] << " | " << grid[12][l] 
		 << " | " << grid[12][m];
}

//
//get coordinates
//int BattleGrid::markSpot()
//{
//	if (guess == grid[0][a])
//	{
//		//put x that marks the the battleship
//		
//	}
//	else
//		// put an o that marks the spot

			//or
//
//		

	//if (guess == x[ROW] && guess == y[COLUMN])
	//	{
	//		//put x that marks the the battleship
	//		
	//	}
	//	else
//		
//
//			// put an o that marks the spot
//
//}

//randomly places the battleships in grid
//2d array have 169 spots(13*13)?
void BattleGrid::scatterBattleships()
{
	int a,b,c,d,e;		//stores random numbers

	a = rand()%169 + 1;	// stores random # in a.
	b = rand()%169 + 1;	//stores random # in b.
	c = rand()%169 + 1;	//stores random # in c.
	d = rand()%169 + 1;	//stores random # in d.
	e = rand()%169 + 1;	//stores random # in e.

	//randomly places battles ships in battlegrid?
	airCraftCarrier[5] = a;				
	battleShip[4] = b;					
	destroyer[3] = c;					
	submarine[3] = d;					
	patrolBoat[2] = e;					
}

in your preprocessor add :

using std::vector;

Use the rand function in your library to place the battleship in random
spot.
Something like this :

void placeRandomly(){
  int x = rand()%MAP_SIZEX;
  int y = rand()%MAP_SIZEY;
  this.place(bigShip, x , y);
}

In this code:

void placeRandomly(){
  int x = rand()%MAP_SIZEX;
  int y = rand()%MAP_SIZEY;
  this.place(bigShip, x , y);
}

Are the MAP_SIZEX & MAP_SIZEY built in features or would i have adjust the code of however i have it setup?

Another question is, would i use the same code to scattered the battleships like this:

void placeRandomly()
{
  int x = rand()%MAP_SIZEX;
  int y = rand()%MAP_SIZEY;

  this.place(airCraftCarrier[], x , y);  //airCraftCarrier array
  this.place(battleShip[], x , y);
  this.place(destroyer[], x , y);
  this.place(submarine[], x , y);
  this.place(patrolBoat[], x , y);
}

Would i use a pointer for the airCraftCarrier(e.g. *airCraftCarrier)?

Thanks!

in your preprocessor add :

using std::vector;

Use the rand function in your library to place the battleship in random
spot.
Something like this :

void placeRandomly(){
  int x = rand()%MAP_SIZEX;
  int y = rand()%MAP_SIZEY;
  this.place(bigShip, x , y);
}

end quote.

>>Are the MAP_SIZEX & MAP_SIZEY built in features

No they are the limit of your map size in row and column, are you
using a 2d array as your map ?

>>Another question is, would i use the same code to scattered the battleships like this:

void placeRandomly()
{
  int x = rand()%MAP_SIZEX;
  int y = rand()%MAP_SIZEY;
 
  this.place(airCraftCarrier[], x , y);  //airCraftCarrier array
  this.place(battleShip[], x , y);
  this.place(destroyer[], x , y);
  this.place(submarine[], x , y);
  this.place(patrolBoat[], x , y);
}

It depends on your place function, if its function prototype is like so :

place(int shipType[], int size,int x, int y);

Then your function call would look something like so :

this.place(battleShip,battleShip.size(),x,y);

But I am not sure how you are representing your battle ship so I cannot say for sure.

Yes, I'm using a 2d array as my map. Thanks for the help, i appreciate it!

>>Are the MAP_SIZEX & MAP_SIZEY built in features

No they are the limit of your map size in row and column, are you
using a 2d array as your map ?

>>Another question is, would i use the same code to scattered the battleships like this:

void placeRandomly()
{
  int x = rand()%MAP_SIZEX;
  int y = rand()%MAP_SIZEY;
 
  this.place(airCraftCarrier[], x , y);  //airCraftCarrier array
  this.place(battleShip[], x , y);
  this.place(destroyer[], x , y);
  this.place(submarine[], x , y);
  this.place(patrolBoat[], x , y);
}

It depends on your place function, if its function prototype is like so :

place(int shipType[], int size,int x, int y);

Then your function call would look something like so :

this.place(battleShip,battleShip.size(),x,y);

But I am not sure how you are representing your battle ship so I cannot say for sure.

>>Yes, I'm using a 2d array as my map. Thanks for the help, i appreciate it!
Ok then your 2d has a limit in its row and column, that limit will be your
MAP_SIZE_X and MAP_SIZE_Z.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.