creating a tree pattern using looping

I am having trouble trying to create this the way my professor wants. this is what is required from us:
Write a complete program that prints out a “tree” of asterisks with the number of lines specified by the user. For example, the following output is a five-line tree:
1 *
2 ***
3 *****
4 *******
5 *********

• Your program should prompt the user to enter the number of lines.
• The number of lines should be between 1 and 30, inclusive. If the user enters a non-positive integer (0 or negative), display a message indicating that the number of lines must be at least 1 and re-prompt for the number of lines. Continue to print the error message and re-prompt until the user enters a valid number, 1 or more.
• In addition, you are to limit the number of lines to a maximum of 30, so, if the user enters a number greater than 30, accept the input, but display a message indicating that the number of lines is too large and the program is defaulting to the maximum of 30 lines, then print out a 30-line tree.
• For test purposes include the line number on each line of the tree. Be sure to right-align line numbers in a two-character field so single-digit line numbers align nicely with double-digit line numbers.
• The program must also ask the user if he/she wants to output another tree pattern, and, if the answer is ‘y’ (upper or lower case) for “yes”, repeat from the beginning (ask the user to enter the number of lines, etc.), otherwise exit (for any user input other than the letter y).

and this is what I have:
#include <iostream>
int main (void)

{
using namespace std;

int i;
int l;
for (i=1; i<=10; i++)
{
for (l=1; l<=i; l++)
cout<< "*";
cout<< endl;
}

system("pause");
return 0;
}
any help would be great
What are you having difficulty with? All the bullet points? Or understanding what each one means? If it is the bullet points then try and do the first one and post back the code you come up with and we'll take it from there.
The problem I have is one he asks use to do a right align which I dont know how to do and also he asks to make the program so that it asks the user to enter the number of lines but when you compile mine it automatically forms the lines it doesnt ask the user for anything
Last edited on
Ok well i just made this program (only using the two conditions from the post above this) and its not that hard, not even for a beginner. All you need to know is basic I/O, if statements and loops. But from your last post i'm guessing you haven't done much work in c++ because getting user input is like one of the first things you learn.
Last edited on
Topic archived. No new replies allowed.