Hi everyone, my current assignment is to make two triangles out of asterisks with a width and height of a given integer (between 1 and 15).
Now, I have completed the first, as the vertex of the triangle is left justified, however on the next I need it to be right justified, and I cannot for the life of me accomplish this. I have tried several things, including tinkering with the counters, trying to include spaces, and string manipulators, but none of these things work.
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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
for (int n = x ; n >= 1; n--)
{
for (int k = 2; k <= n; k++)
{
cout << " ";
}
for (int j = 1; j <= n ; j++)
{
cout << '*';
}
cout << endl;
}
system ("pause");
return 0;
}
|
This is what I currently have. I cut out the parts of the program that aren't relevant to this portion of the problem (I have test the rest and it works), it's just that this is what's causing me issues. The for statement produces the correct number of spaces needed to complete the triangle, however it produces them in the opposite order each line (for example, if x is entered as 5, it produces 4 spaces on the first line and 0 on the 5th, which I need the opposite to happen).
Thanks for the help you guys!