### Making a pyramid program

I want the output to look something like this:

 ``` Enter a value to represent the base of a triangle shape (not to exceed 80): 11 Enter the character to be used to generate the triangle shape (for eg., #, * \$): * * *** ***** ******* ********* ***********Do you want to quit the program? (type n for no or q to quit): q```

My incorrect source code to attempt to acheive this exact output so far is:

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include #include using namespace std; int main() { int stars=1; int baseNumberStars; char theSymbol; string spaces = " "; cout << "Enter a value to represent the base of a triangle shape (not to exceed 80): "; cin >> baseNumberStars; cout << "Enter the character to be used to generate the triangle shape (for eg., #, * \$): "; cin >> theSymbol; if (baseNumberStars>80) { cout << "Please enter a number 1-80 for triangle's base.\n"; system("PAUSE"); return(1); } if((baseNumberStars>0) || (baseNumberStars<=80)) { for(int line=-1; line < baseNumberStars; line++) { for(int s=(baseNumberStars-1); s < stars; s++) cout <

I am very new to loops and am learning them for the first time so bear with me...
The things I need to do left for my program are:

1. I need to get it so my triangle is no longer a right triangle.
2. I need to make it so at the end of the program when "n" is inputted it repeats the program.

Also, I am confused why there is a large space between my triangle and the words above it.

I may not respond for a few hours or so after this. Your guys help appreciated, thanks again.
Last edited on
OP wrote:
2. I need to make it so at the end of the program when "n" is inputted it repeats the program.

Then read the input in a char(or any other thing), and break; the loop if q, do nothing if n, --optional-- or say something like "Wrong input" if any other character.

Working on the code.

Thanks,
Aceix.
At last solution found!--at least for the second question.
The problem is that, the tip is not pointed, and it also doubles the base of the triangle.--Maybe someone might try to help "us" out?

Code:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include #include using namespace std; void print_triangle(int,char); int main() { int iTriangleBase=0; char cTriangleStyle='*'; char cExitCode; do { cExitCode=0; cout<<"Enter number for the base of the triangle(Note**Number would be doubled!**): "; cin>>iTriangleBase; cout<<"Enter style for triangle block: "; cin>>cTriangleStyle; print_triangle(iTriangleBase,cTriangleStyle); while(cExitCode!='q'&&cExitCode!='n') { cout<<"\n\nDo you want to quit(q) or stay(n): "; cin>>cExitCode; if(cExitCode!='n'&&cExitCode!='q') cout<<"\nWrong Input!!!"; } }while(cExitCode!='q'); return 0; } void print_triangle(int iBase,char cStyle) { static int iTop=0; int iSpaces=iBase; int iTemp1,iTemp2; for(int i=1;iSpaces;iSpaces--,i++) { for(iTemp1=iSpaces;iTemp1;iTemp1--) { cout<<' '; } for(iTemp2=0;iTemp2!=i;iTemp2++) { cout<

Thanks,
Aceix.
Topic archived. No new replies allowed.