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!
#include <iostream>
usingnamespace 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;
}
}
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