Segmentation error in Battleship game

I am getting segmentation error but I don't know whats happening. I isolated it to this part. I want to mark the grid with the first letter of whatever the ship is called. For example, Battleship would be "B" and because the battleship is 4 grids long it would be.. B B B B

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
int markBoard(int posx, int posy, string angle, int length, string image) //WORKING ON THIS PARTĶ
{
    posx-=1;
    posy-=1;

    if (angle=="v")
    {

        posx+=length;



        for(int x; x<posx; x++)
        {
            playboard[posy][x]={"\bB"};
        }
    }

    if (angle=="h")
    {
        posy+=length;

        for(int y=posy; y<posy; y++)
        {
            playboard[posx][y]={"\bB"};
        }
    }
cout << posx << endl;


Thanks in advance!

Full program is here. Won't let me post it here.


FULL PROGRAM HERE if needed:
http://cpp.sh/9yy3
In this particular function, it seems as if you're trying to print outside the function. I think you forgot a brace on line 29.

So, maybe when you call the function, you're getting an error?
On line 13, x is not initialised. Always initialise your variables to something, it's one of the biggest problems.

3
4
  posx-=1;
    posy-=1;


These can be more concisely written:

1
2
--posx;
--posy;
> FULL PROGRAM HERE if needed:
you should always provide enough code to reproduce your problem.
Given that you have a runtime error, that means `main()' and anything that it needs to compile and run.

Your program ask for input, so provide an example one.
Topic archived. No new replies allowed.