How to make a propeller shape using for loops?


The ouput should be like this:

Enter size : 5

.....*****
*....****
**...***
***..**
****.*
*****.*****
.....*.****
....**..***
...***...**
..****....*
.*****


(dots are the number of spaces between each right trianles)

I've tried many times but I still can't get it .

#include <iostream>
using namespace std;
int main ()
{

int size;

cout << "Enter a number for the size : " ;
cin >> size;

cout <<endl;


for (int i = 0; i <= size; i++)
{
for(int x = 0; x <= i; x++)
{
cout << "*";
}
for( x = 0; x < size; x++)
{
cout <<" ";
}
for( x = 0; x < size; x++)
{
cout <<"*";
}
for( x = 0; x <= i; x++)
{
cout << " ";
}
for( x = 0; x <= i; x++)
{
cout << " ";
}
for( x = 0; x < size; x++)
{
cout <<"*";
}
for( x = 0; x < size; x++)
{
cout <<" ";
}
for( x = 0; x <= i; x++)
{
cout << "*";
}
size--;
cout << endl;
}


return 0;
}
what exactly is this propeller shape supposed to look like with spaces? try the
[output]
[/output] tags. Also please use
[code][/code]
tags around code please makes it easier to read. The only other problem I see is you are using a lot of for loops. Have you used iomanip before? They have a function called std::setfill and std::setw where you can set the filling character and the width.

http://www.cplusplus.com/reference/iomanip/
http://www.cplusplus.com/reference/iomanip/setfill/
http://www.cplusplus.com/reference/iomanip/setw/
thanks but i dont know how to use [output] . icant type it exactly what it look like . im sorry
Just type "output" text you want to represent as output "/output" (with brackets instead of the quotes)

That'll make it display like this. (I think this is what it should look like? I took out a space on each line at the bottom left.)

.....*****
*....****
**...***
***..**
****.*
*****.*****
....*.****
...**..***
..***...**
.****....*
*****



or like this?

*....*****
**...****
***..***
****.**
******
....******
...**.****
..***..***
.****...**
*****....*
Last edited on
Topic archived. No new replies allowed.