Use spaces as padding. Since a space is always the same length (as is a *), it's easy to calculate the amount of spaces required. It gets much easier if you decide to use only uneven amount of *s.
Since you have the answer now, here's my solution. Same as BlackOut's, but a dynamic stump creation, whereas it will make the stump based on the size of the tree:
int _tmain(int argc, _TCHAR* argv[])
{
int stars = 1;
//size is all you need to change, to automatically
//change the size of the stump
//size of tree in height
int size = 10;
int stumpHeight = size / 3;
int stumpWidth = size / 2;
for( int total = size; total > 0; --total )
{
//control the amount of spaces
for( int i = ( total - 1 ); i > 0; --i )
std::cout << " ";
//control the amount of stars
for( int j = 0; j < stars ; ++j )
std::cout << "*";
//next row needs 2 extra stars
stars += 2;
std::cout << '\n';
}
//create the stump
for( int i = 0; i < stumpHeight; ++i )
{
//spaces to the center of the tree
//so that the stump is centered
for( int j = 0; j < ( size - ( stumpWidth - ( stumpWidth / 2 ) ) ); ++j )
std::cout << " ";
for( int k = 0; k < stumpWidth; ++k )
std::cout << "*";
std::cout << '\n';
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
//for a random number
srand( unsigned( time( NULL ) ) );
/*///////////////////*/
/* Controls: */
/*///////////////////*/
//size of tree in height
int size = 20;
//percentage of decorations
int percentage = 25;
/* Visual */
//tree top
char treeTop = '^';
//tree stump
char treeStump = '|';
char pot = ( char )219;
//character for decoration
char decoration = 'o';
/*///////////////////*/
//first star
int stars = 1;
int stumpHeight = size / 3;
int stumpWidth = size / 3;
int potHeight = stumpHeight / 2;
int potWidth = stumpWidth + 2;
int randomNumber = 0;
for( int total = size; total > 0; --total )
{
//control the amount of spaces
for( int i = ( total - 1 ); i > 0; --i )
std::cout << " ";
//control the amount of stars
for( int j = 0; j < stars ; ++j )
{
randomNumber = rand() % 100 + 1;
//decorations wont go on the outline of the tree
if( ( j > 0 ) && ( ( stars - j ) > 1 ) )
{
if( randomNumber < percentage )
std::cout << decoration;
else
std::cout << treeTop;
}
else
std::cout << treeTop;
}
//next row needs 2 extra stars
stars += 2;
std::cout << '\n';
}
//create the stump
for( int i = 0; i < stumpHeight; ++i )
{
//spaces to the center of the tree
//so that the stump is centered
for( int j = 0; j < ( size - ( stumpWidth - ( stumpWidth / 2 ) ) ); ++j )
std::cout << " ";
for( int k = 0; k < stumpWidth; ++k )
std::cout << treeStump;
std::cout << '\n';
}
//create the plant pot
for( int i = 0; i < potHeight; ++i )
{
//spaces to the center of the tree
//so that the stump is centered
for( int j = 0; j < ( size - ( potWidth - ( potWidth / 2 ) ) ); ++j )
std::cout << " ";
for( int k = 0; k < potWidth; ++k )
std::cout << pot;
std::cout << '\n';
}
return 0;
}