help!

Hello guys.

I got stuck as below.
Also I am tring to creat triangle as "*"&"space" as below.


*
**
***
****
*****
******
*******
********
*********
**********



for (int i=0; i<=10; i++){

for(int j=0; j>i; j++){
cout << "*";
}
for(int j=i; j<10; j++)
{
cout << " ";
}
cout << endl;
}



but it doesn't show anything. I am wondering why it doesn't.
If you can correct me, please let me know.

Thanks
Yoshi
Last edited on
Not a biggie. You just did one of the loop conditions wrong.

1
2
3
4
5
6
7
8
9
10
11
for (int i=0; i<=10; i++){ 

for(int j=0; j<i; j++){      // You had this as greater than before, which 
cout << "*";                 // would have skipped over this loop every time
}
for(int j=i; j<10; j++)
{
cout << " ";
}
cout << endl;
}

You don't really need the spaces. It looks the same even if you don't print them. I would just erase that last for loop.
Last edited on
Hi Billdozer,

Thanks your comments.
I tried to do your advisement, but it didn't work...

Thanks
Yoshi
The Billdozer advisement was good.
I tried it and it works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream.h>
#include <conio.h>

void main() {
	for (int i=0; i<=10; i++) {
		for(int j=0; j<i; j++) {
			cout << "*";
		}
		for(int j=i; j<10; j++) {
			cout << " ";
		}
		cout << endl;
	}
	getch();
}
Sorry guys,

I did wrong the triangles.
The direction was opposite for that.
I changed the above triangle.
Also finally I heard of my teacher.
The triangle needs three variables as below.

for (int j = 10; j > 0; j--) {
for(int i = 1; i < j; i++) {
cout << ' ';
}
for(int n = 10; n >= j; n--) {
cout << '*';
}
cout << endl;

It was a good lesson for increasing my knowledge in my empty head!

Thanks!
yoshi

P.S. Sorry again. the above triangle couldn't fix for differet direction which I want to!
Last edited on
Topic archived. No new replies allowed.