Can any one help or give some good advice on where I need to go from a point in my code. I am building an asterisks tree and I managed to get that part done, but there are three thing I need to input to complete the assignment.
1. And the line numbers to the asterisks.
2. Limit the asterisks tree to only 30 lines
3. If user does input more than 30 lines, program defaults to printing 30 asterisk lines with an message saying 'limit is 30 lines'
I pretty much have everything else done. here is the code:
****p.s please do include stdio library..I am not that far yet****
#include <iostream>
#include <iomanip>
using namespace std;
const int min_lines = 1; //We want a minimum and maximum set
const int max_lines = 30;
int main()
{
int lines, //This is the amount of lines you want
spaces; //This is for your spaces
char answer; //To continue later, your answer will be in a for of
//a letter
//Beginning of our program...Let's make a tree!
cout << "We are going to make a tree of sterisks.\n"
<< endl;
cout << "Please enter in your desired amount of lines for your
<< "tree."
<< "\nNote: Your input must be between 1 and 30 lines."
<< endl;
cin >> lines; //Input the amount of lines desired.
//The loop variable will begin here.
for (spaces = 0; spaces < lines; spaces++ )
{ cout << setfill (' ') << setw (lines - spaces - min_lines) <<
<< "";
cout << setfill ('*') << setw (spaces * 2 + min_lines)
<<""<< endl;
} //end of 'for' loop
cout << "\n" << endl; //To continue or end the
//program
cout << "Do you wish to try another set of lines?\n" << endl;
cout << "Type 'y' to continue and 'n' to quit\n" << endl;
cin >> answer;
cout << "" << endl; //Below is just in case
//someone does not press 'y' or 'n'
if (answer >= 'a' && answer <= 'm' || answer >= 'o' &&
answer <= 'x' || answer == 'z')
{ cout << "Invalid entry.\n" << endl;
cout << "Please type in 'y' to continue or 'n' to end the
<< "program" << endl;
cin >> answer;
cout << "" << endl;
}
while (answer != 'n' ) //The 'while' loop is needed to
//continue asking to 'continue'
{ //with the program
cout << "Please enter in your desired amount of lines for your
<< "tree." << endl;
cout << ' ' <<endl;
cin >> lines;
cout << "\n" <<endl;
for (spaces = 0; spaces < lines; spaces++ )
{ cout << setfill (' ') << setw (lines - spaces -
<< min_lines) << "";
cout << setfill ('*') << setw (spaces * 2 +
<< min_lines) <<""<< endl;
}
cout << "\n" << endl;
cout << "Do you wish to try another set of lines?\n" << endl;
cout << "Type 'y' to continue and 'n' to quit\n" << endl;
cin >> answer;
} //end of 'while' loop
return 0;
}