This new thread is practically a continuation of my last Triangle problem. The reason I posted this separately is just to ensure I can receive feedback right away.
Thanks! I understand perfectly.
Now, I have to create a triangle that displays like this, in this case, when the height is 11:
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
The difference is apparent. The user must input a positive odd integer value. The amount of stars printed on each line increases by 2 as we go from line 1 up to the middle part, where 11 (for instance) or the input value of stars is printed. Going downhill, the number of stars begins to decrease by 2, until only 1 star is printed (like in the beginning). I've tried to make some changes on the original triangle program code, but so far I haven't suceeded.
My code from last time, which I fixed, looks like:
Code:
/*Project 53
Herbert Ortiz
Due: October 11, 2004
This programs prompts the user to input a positive odd integer value: And
based on this information, print a triangle as the output*/
#include <stdio.h>
#include <conio.h>
#include <assert.h>
void PrintTop(int linenumber); //this function will print the top triangle portion
void PrintBottom(int linenumber2); //this one will print the bottom portion
main()
{
int linenumber, linenumber2; //local variables declared for use in the loops
int height; //input variable is declared here
printf("Enter the height of the triangle: "); //prompt
scanf("%d", &height); //height is stored in memory for evaluation in the loop
assert(height>0); //error handler
for(linenumber=0; linenumber<height; linenumber++) //the for loop dealing with top triangle portion
{
PrintTop(linenumber); //function call for top portion of triangle
}
for(linenumber2=height; linenumber2>=0; linenumber2--) //for loop dealing with bottom triangle portion
{
PrintBottom(linenumber2); //function call for bottom portion
}
system("PAUSE");
}
void PrintTop(int linenumber) //function header and definition
{
int i; //variable i is used for the for loop here
for(i=0; i<linenumber; i=i+2) //for loop that will print first output
{
printf("*");
}
printf("\n");
}
void PrintBottom(int linenumber2) //function header and definition
{
int j; //j is used for the following for loop
for(j=linenumber2; j>0; j=j-2) //this loop prints the bottom triangle piece
{
printf("*");
}
printf("\n");
}
Please help me. Thanks!