>>At the end I need a way to ask if I want to get another tree.
You could move the break; in your while and try
1 2 3 4 5 6 7 8
}
cout << "Would you like to draw another tree? (y/n): ";
cin >> answer; // where answer is a char
if (answer == 'y') continue; // run loop again
elseif (answer == 'n') break; // exit while loop
else MyErrorHandler(); // you may wish to handle cin going into the fail state
// or answers not equal to 'y' or 'n'
}
Since this is an exercise in "algorithm building", i would suggest getting out a piece of graph paper (or printing one from http://incompetech.com/graphpaper/plain ). Then, use the graph paper to draw the trees as they would look for each line count starting with line count of 1 .. then 2 .. and so on.
Your goal is to find the general pattern. Questions like "how far over from the left does the first asterisk have to start" and "how long is the last row depending on the number of lines chosen" are important.
Sorry, lost internet in the middle of our conversation.
While it was down, I did work out what you need to do. Although, I still feel that you need to take the previous suggestion of using graphpaper to draw the trees out and look for the patterns. (this is what i did)
Hints:
1) Print blanks in a loop to move the asterisks over. Or use the setw() function. cout << setw(5) << '*';
This will print the asterisk in the 5th column.
2) Once you figure out where the first asterisk goes, the following rows are just one column sooner on each print.