# Thread: Just in case: "Odd" Triangle Challenge (for me)

1. ## Just in case: "Odd" Triangle Challenge (for me)

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");
}```

2. Why do you need help? If you can print the triangle right side up, you can print it upside down. What's the problem? And stop I am sillyI am sillyI am sillyI am sillying spamming the board! Read the Announcements.

Quzah.

3. ## ?

What are you talking about? I stated clearly what the triangle should look like. If you read it, it says the number of stars increases by 2 as I reach the "height" or tip of the triangle.
The changes to be made are in my for loops, if my guessing's right.

4. > void PrintTop(int linenumber); //this function will print the top triangle portion
> void PrintBottom(int linenumber2); //this one will print the bottom portion
If you look closely, you'll see that both functions do the same thing - namely print 'n' stars

> assert(height>0); //error handler
Use if statements for user input not assert()
assert() is used for trapping programming errors

> The amount of stars printed on each line increases by 2 as we go from line 1 up to the middle part
Try swapping which loops get the +2 and -2
You have them on the inner loops (which result in flat triangles)