Designing a tree figure

Moved
Last edited on
>>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
else if (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'
}


Hope that's helpful.
Thanks Cazicss,

By any chance would you know how to make the *'s line up to look like a tree. And get it to add 2 *'s for each line except for line 1

Everything else is good. Just needed that little bit of help. Greatly appreciate it.
Last edited on
>>make the *'s line up to look like a tree.

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.
Last edited on
Well my max number of lines is 30.

Line 1 should be 1 star
Line 2 is 1+2 stars....and so on. With each line after that its two stars added with each row.

I can set a width of 59 which would be the correct width of Line 30

The amount of spaces between the Line # and * would start at 29 and then go down from there.

So how would I integrate this idea into my code.
Quick question,
did you say this was the correct output for 3 lines?

Line 1 *
Line 2 ***
Line 3 *****
Yes that would be the correct amount of stars, but some how the stars need to be centered on each other

Like so

Line 1 *
Line 2 ***
Line 3 *****

So I'm trying to figure out how to get the addition of 2stars after line 1 and then getting them all centered base on the number of stars on base
Im sorry but im not seeing a difference in the stars u just put up and the 3 lines i did before ...
you mean like this instead?

Line 1 -----*
Line 2 ---***
Line 3 -******


I put in dashes to avoid the asterisks being pushed to left as in your previous post. That is assuming that this is what you meant by centered.
Last edited on
Yes that is what I need more or less. But I also haven't figured out the thing with adding ** to each line after Line 1.
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.
Last edited on
Topic archived. No new replies allowed.