I am trying to center the triangle, but I have no idea how.
I am trying to make a triangle like below:

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

(this is not the one I want, the format screws up)
I kind of forgot, do i use something like printf?

#include <iostream.h>
#include <conio.h>

main()
{
   int height;
   int i = 1;

	cout << "height?";
   cin >> height;

   while(i<=height)
   {
   	for(int j=0; j<i; j++)
      {
      	cout << "*";
      }
      cout << endl;
      i=i+2;
   }


   /*
   i = height - 2;
   while(i>=1)
   {
   	for(int j=0;j<i;j++)
      {
      	cout << "*";
      }
      cout << endl;
      i = i - 2;

   }       */
   getch();
}

Edited 6 Years Ago by WaltP: Why not try CODE tags since the work for code? And the PREVIEW button!

Are you trying something like this?

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

yes. But I dont't know how. Is there like a source code or anything for it?

Comments
Did you bother to look at my post?

yes. But I dont't know how. Is there like a source code or anything for it?

  1. 4 lines
  2. Number of asterisks in the line is a formula based on the line number.
  3. Number of spaces before the first asterisk is a formula based on the line number.
for (int i = 0; i < someNumber; i++)
{
    // make a loop to print the spaces.
    // make a loop to print the asterisks.
    // display a newline.
}

Edited 6 Years Ago by VernonDozier: n/a

Comments
Short and exact

>Is there like a source code or anything for it?
Obviously there is a source code but you have to figure it out. Just follow the tips Vernon has given and you should do fine. If you are still uncomfortable, can you print this triangle?

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

If you can, then your original problem is just a modification of this one. Just think about this...
If you can't, then pursue this one first.

I love being ignored.

I'll try 1 more time...

So what's missing in your triangle?
What is necessary to get the *s in the right spot?

This article has been dead for over six months. Start a new discussion instead.