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.


The code I've made is stuck in an infinite loop and I cannot figure out why D:

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
#include <iostream>
using namespace std;

int main()
{
	int x = 1;
	do {
		
		int b = 10;
		do
		{
			int a = 10;
			do
			{
				cout << "*"; // Prints stars
				a--;
			} while (a <= b);

			cout << endl;
			b--;
		} while (b <= 1);
		
		x++;
	} while (x <= 1); // using this later to duplicate my pattern
	system("pause");
	return 0;
}
Last edited on
Maybe try
17 } while (a >= b);
and
21 } while (b >= 1);
Try this:
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>

int main()
{
    int stars, s, i;
    
    std::cout << "How many stars? (0 - 10):\t"; //asks for users input.
    std::cin  >> stars; //Grabs input.
    
    if(stars > 10 || stars < 0) //Makes sure input is between 0 and 10.
    {
        std::cout << "Number was not usable.";
        
        return -1; //Exit program.
    }
    
    i = 10 - stars;//Sets how many spaces(white spaces)
    
    while(i != 0) //Prints correct amount of spaces. (white space.)
    {
        std::cout << " ";
        --i;
    }
    
    s = stars; //Sets stars "*"
    
    while(s != 0) //Prints correct amount of stars.
    {
        std::cout << "*";
        --s;
    }
}


**updated script.
Last edited on
here you go . As you can see , put a relevant name to variable , otherwise what would be the meaning of having a variable try this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
unsigned int col = 10;
unsigned int row = 10;

int line = 0;
for ( ; line < row ; ++ line)
{
	for(int space = 0 ; space < line ; ++ space)
		std::cout << " " ;
	for(int star = line ; star < col ; ++ star)
		std::cout << "*" ;

	std::cout << std::endl ;
}

	system("pause");
	return EXIT_SUCCESS;
Am I crazy or did I see this question in another thread ?

Edited


You do need to post the same in different categories . A least if it was not reply in a day or two . We are trying to help by compiling your code and fixing it in our machine . It takes time sometime because we , programmers , work also do not forget that either . I am simply saying that because for someone looking too for that an answer to that It will be easier if there was only a thread for this .

Have a nice day.

Ericool.
Last edited on
@Ericool

Nope, you're NOT crazy. This IS a double post. Original is here..
http://www.cplusplus.com/forum/beginner/172688/

ok then. :)
Topic archived. No new replies allowed.