Been working on a small project designed to print a hollow diamond.
I'm pretty much there but have been having trouble fixing a minor problem.
The diagonal line of my diamond running from the 12 o'clock to the 3 o'clock position is consistently '1 space to the left' of where it should be. Can't for the life of me figure out how to get this extra space in without everything else going to tits!
#include <iostream>
usingnamespace std;
int main()
{
int n;
cout << "Enter Diamond Width: ";
cin >> n;
for (int i=0; i < n; i++) /* This loop controls the TOP line */
cout << " ";
cout << "A" << endl; /* "A" is being used as an example user boarder input */
for (int i = 1; i < n-1; i++)
{
for (int j = n-2; j >= i; j--)
cout << " ";
cout << "A";
for (int k = (n-2)/3; k <= i * 2; k++)
cout << " ";
cout << "A" << endl;
}
for (int i = 0; i < n-1; i++)
{
for (int j = 0; j < i; j++)
cout << " ";
cout << "A";
for (int k = (n-1)*2; k >= i * 2; k--)
cout << " ";
cout << "A" << endl;
}
for (int i = 0; i < n; i++) /* This loop controls the BOTTOM line */
cout << " ";
cout << "A";
}
I think the problem lies in line 29 - the "k = (n-2)/3" bit. So close I can almost taste it but then again the most annoying problems are always at the end huh?
Any help is much appreciated!
Apologies if my forum/code formatting is not up to scratch. Newb to both!
Edit: Turns out its not 'one space' behind, it seems to change dependent on the size of the inputted value - which unfortunately makes the problem more of a pain in the butt
I noticed a nice little patter using the absolute value function. It usually looks like a really sharp right angle so I figured it might be able to do a diamond pretty well.