Star program backwards!

I am trying to print out a star program that prints out a series of "*" in
the desired form:

********** (10)
||********* (9)
|||******** (8)
|||||******* (7)
||||||****** (6)
|||||||***** (etc...)
||||||||****
|||||||||***
||||||||||**
|||||||||||*

Just imagine the "|" as white space, can't seem to get it to post correctly without them.

I can't get the correct output, My code is below:

Please note I am trying to do this specifically with do while loops!!
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
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;

int main()
{
	int column = 10;
	int row = 10;
	int line = 0;
	int star = 0;
	int space = 0;

	do
	{
		do

		{

			cout << " ";
			space++;
		}

		while (space < line);

		do {
		
			cout << "*";
			star++;

		}

		while (star < column);
		
		cout << endl;

	} while (line++ < row);

	system("pause");
	return 0;
}
Last edited on
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
30
31
32
33
#include <iostream>
using namespace std;

int main()
{
	int column = 10;
	int row = 10;
	int line = 0;
	int star = 0;
	int space = 0;

	do
	{
	    space = -1;
	    do
	    {
	  	cout << "&";
		space++;
	    } while (space < line);

            star = space;
	    do {	
		cout << "*";
	        star++;
	    } while (star < column+1);
		
	    cout << endl;

	} while (line++ < row);

	system("pause");
	return 0;
}

Last edited on
Maybe what you posted is what you want, but if the first line has 10 stars, the next line should have 8 or it's not going to look centered. So my first question is, do you want the stars to line up on the right, or centered down the middle ?



Maybe this will be close to your goal
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
30
31
32
#include <iostream>
using namespace std;

int main()
{
	int column = 10;
	int row = 10;
	int line = 0;
	int star = 10;
	int space = 0;

	do
	{

		do
		{
			cout << " ";
		} while (space++ < line);
		space=line/2;

		do
		{
			cout << "*";
		} while (star-- > 0 );
		star=row-line-1;

		cout << endl;

	} while (line++ < row);

return 0;
}
The do while does always at least one iteration. If you print the leading space with do while for each row, then every row will have at least one space.


Use the 'output' tags to format text in your post to get verbatim, fixed-width characters.
Topic archived. No new replies allowed.