Hey, I am trying to make a function for a larger battleship game, but I am getting errors that my TA didn't know how to fix either, so I thought I'd try my luck here.
Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define CARRIER_LENGTH 5
void randomlyPlaceShipsOnBoard()
{
int direction = 0, row = 0, column = 0, i = 0;
direction = rand() % 2;
if (direction == 0)
{
column = rand() % 10;
row = rand() % 10 * (11-CARRIER_LENGTH); Error 7 is here
}
else
{
column = rand() % 10 * (11-CARRIER_LENGTH); Error 8 is here
row = rand() % 10;
}
while (i < CARRIER_LENGTH) Error 9 is here, which is confusing because there's no '='
{
if (gameBoard[row][column] != '~')
{
status = 1;
}
i++; Errors 10 and 11 are here
row++; Errors 12 and 13 are here
} Error 14 is here
}
The error messages are:
Error 7 error C2059: syntax error : '='
Error 8 error C2059: syntax error : '='
Error 9 error C2059: syntax error : '='
Error 10 error C2143: syntax error : missing '{' before '++'
Error 11 error C2059: syntax error : '++'
Error 12 error C2143: syntax error : missing '{' before '++'
Error 13 error C2059: syntax error : '++'
Error 14 error C2059: syntax error : '}'
As always, the help is much appreciated, and I'm open to any suggestions for improvements..