Making these horizontal lines vertical

Hey all! Been racking my brain working on getting the horizontal lines within the diamond trying to make them vertical.

I'm guessing that I need to take the if-else pair (line 32) outside of the brackets and perhaps upwards beneath the initial for loop (line 19) but anything i try results in disaster!

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>

using namespace std;

int main()
{
   int n;
   int j;
   char border;
   char fill;

   cout << "Enter Diamond radius: ";
   cin >> n;
   cout << "Enter border character: ";
   cin >> border;
   cout << "Enter a fill character: ";
   cin >> fill;
   
   for (int i = (1-n); i < n; i++)
	{
		for (j = 0; j < abs(i); j++)
		{ //outer spaces
			cout << " ";
		}	

      cout << border;

		if(abs(i) != (n-1)) //if not the first or last row, print a second "A"
			{
				for (int k = 1; k < 2*((n-1)-abs(i)); k++)
					{ //inner spaces
						if (j % 2 == 0) //if on an even row output spaces
							{
								cout << " ";
							}
						else //if on an odd row output the fill character
							{
								cout << fill;
							}
			
					}
						cout << border;
			}

		cout << endl;
   }
}


Thanks guys!
I think you need to include this line...
# include <cmath>
To get them vertical?

All works fine without it. Why is it necessary?
On line 32 replace j with (k+i)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
         x
        xdx
       x d x
      xd d dx
     x d d d x
    xd d d d dx
   x d d d d d x
  xd d d d d d dx
 x d d d d d d d x
xd d d d d d d d dx
 x d d d d d d d x
  xd d d d d d dx
   x d d d d d x
    xd d d d dx
     x d d d x
      xd d dx
       x d x
        xdx
         x
I cant believe it was so simple! Thankyou so much!
Topic archived. No new replies allowed.