btw this is a part of a battleship code
i want to know what the integers a,b,c,d,e,f... do
I know this has something to do with placing ships randomly but it is a little complexed for me. I'd appreciate it if someone took their time to explain it

``````int placeship( int x, int z[ ][ 10 ] )
{
int a, b, c, d, e, f, g, h, i, j, k;
int pc;
int usum, dsum, lsum, rsum;

usum = 0;
dsum = 0;
lsum = 0;
rsum = 0;

pc = 0;

a = rand() % 10;
b = rand() % 10;
c = rand() % 2;

f = a + x;
g = b + x;

e = (x - 1);

for( d = 0; d <= e; d++)

{

i = a - d;

if( z[ i ][ b ] == 1 )

{

usum++;

}

}

for( d = 0; d <= e; d++)

{
j = a + d;

if( z[ j ][ b ] == 1 )
{

dsum++;

}

}

for( d = 0; d <= e; d++)
{

k = b - d;

if( z[ a ][ k ] == 1 )

{

lsum++;

}
}

for( d = 0; d <= e; d++)

{

h = b + d;

if( z[ a ][ h ] == 1 )
{

rsum++;

}

}

if( c != 1 ) // vector: U/D

{

if( f >= 10 )

{

if( usum == 0 )

{

for( d = 0; d <= e; d++) // vector: up ^

{

i = a - d;
z[ i ][ b ] = 1;

}
pc = 1;

}

}

if( f < 10 )

{

if( dsum == 0)

{

for( d = 0; d <= e; d++) // vector: down v

{

j = a + d;
z[ j ][ b ] = 1;

}

pc = 1;

}

}

}

if( c == 1 ) // vector: L/R

{

if( g >= 10 )

{

if( lsum == 0 )

{

for( d = 0; d <= e; d++) // vector: left <-

{

k = b - d;
z[ a ][ k ] = 1;

}

pc = 1;

}

}

if( g < 10 )

{
if( rsum == 0 )

{

for( d = 0; d <= e; d++) // vector: right ->
{
h = b + d;
z[ a ][ h ] = 1;

}

pc = 1;

}

}

}

return pc;

}``````

## All 4 Replies

the reason why no body is helping is that your code is not intended at all, which makes it difficult for us to read. Please format it with proper intendation and the re-post. Also remove all the blank lines in between.

Confusing? Its not just you. We are too confused with this poorly intended code.
Refer here for how to intend correctly (Allman style).

Won't say, you didn't try intending it. But thats not how it is done.......

Duplicate post

You should have properly indented the code on the first thread and posted on same thread instead of creating a new one
(which by the way the formatting isn't any better than the first)

commented: fuk you -1
commented: @OP don't be rude keep it pleasant +1
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.