I need help writing this program, I am stuck, the following are the directions:
This is what I am supposed to do:
1.To start, create an array filled with the character O (for Ocean).
2.Generate a random number to be the index of the Battleship.
3.Allow the user three guesses to find the location of the Battle ship
4.After each guess you should print the board
5.Previously guessed locations should appear as the character X
6.A message should print if the user guesses a previously guessed location
7.After three (incorrect) guesses you win
8.If the user correctly guesses the location, they wine
Problems: It currently does not build it gives me a problem for Size in the statement: char board [SIZE]; & I am unsure why if in the rest of the program it doesn't do it. Also I am unsure on how to print the X's for what the user enters. Thanks.
This is what I currently Have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand (time(NULL));
int SIZE= 10;
char board [SIZE];
int answer;
fill(board, board+10, 'O');
int index = rand() % 11;
cout<<"Let's Play Battleship!!" << endl;
for (int i=0; i<SIZE; i++)
{
cout << board[i] <<" ";
}
cout<< endl;
cout <<"Enter a guess from 0 to 10";
cin >> answer;
if (answer >= 0 && answer < SIZE)
board[answer] = 'X';
return 0;
}
|