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;
}