You could certainly do it that way, but it's excessively complicated. The pattern adjusts predictably for each row, so just keep it simple:
#include <iomanip>
#include <iostream>
using namespace std;
int main(void)
{
int distance = 7;
int i = -1;
while (++i < distance / 2)
cout << setw(i) << "" << '+' << setw(distance - i * 2 - 2) << "" << 'X' << endl;
cout << setw(i) << "" << '*' << endl;
while (--i >= 0)
cout << setw(i) << "" << '+' << setw(distance - i * 2 - 2) << "" << 'X' << endl;
}
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
is because i'm not familiar with the common (more advanced methods) yet.
The method I suggested is simpler and easier for a beginner to understand and/or figure out.
i put your code word for word into the compiler, even down to putting whitespace where you do. thoughts?
What compiler is it?
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
i'm using ssh to access my school's venus account, and am doing my work directly within ssh. is that my problem?
I have no idea how to interpret that into an answer to my question. Regardless, the code is correct; of that I'm quite sure. If your school's compiler doesn't accept it then the compiler is either wrong (unlikely unless it's a pre-standard compiler), or there's some kind of issue in passing the text to the compiler for processing (more likely). Maybe there's an issue with newline conversions in the source code, or control characters, or whatnot.
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58