Hi everyone! I am having trouble with a class assignment (Intro to C++) where I am supposed output three different patterns using loop statements. The patterns where: a square, a upside down triangle, and a right justified triangle. I got the first two ok, but am having a difficult time getting the last one to be right justified. Can anyone help me with this. I have place the manipulator just about everywhere I can think of in the code without the desired result. I need to output:
*
* *
* * *
* * * *
My question is, while working with loops, how do I justify this pattern to the right, or am I just going about this the completely wrong way?
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
int x, y, num;
cout << "Please enter a posative number to determine \n"
<< "how large you would like the shape to be. ";
cin >> num;
for ( x = 1 ; x <= num ; x++ )
{
cout << setw(num * 2);
for ( y = 1 ; y <= x ; y++ )
cout << "* ";
cout << endl;
}
system ("Pause");
return 0;
}