How can I make an upside down triangle?

Hi there, I need help with making a code for an upside triangle. I am suppose to be using functions for example void draw_triangle().
I have a working code for a triangle, but I have no idea how to make an upside down triangle, or a diamond using the same method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include <iostream>

using namespace std;

void draw_triangle( int size, char ch);  //function declaration

int main()
{
    int size, i, j;
    char ch;

    cout << "Please enter your desired size \n";
    cin >> size;

    cout << "Please enter the character \n";
    cin >> ch;


   for ( i =1 ; i <= (size) ; i++)           //this displays the size.
   {

        for (j=0; j <(2*size -i); j++)       //this displays the spaces.
        {
            cout << " ";
        }
        for (j=0; j < 2*i-1; j++)           //this displays the character chosen by the user.
        {
              cout << ch;
        }

        cout <<endl;
   }

  \

    return 0;
}


Thank you!
The idea is to start the outer loop from the other side:
 
for ( i =size ; i >= 1 ; i--)  

To make a diamond, just add two loops together. As not to repeat the largest row of characters, start the second loop from size-1
Well I am not going to give the exact code as I think that is irrelevant to your problem. Lets say the top of triangle ie the max number of characters is 4... So what is the relationship between the top of the triangle and the bottom of the triangle. Keep in mind this is output (i am guessing) is suppose to look like for the function

 
* * * * 
 * * *
  * *
   *


Now this comes down observing the pattern of the triangle, in the triangle demonstrated in the output all I did was with each row I increased the amount of initially spaces by 1. For example, in the first row there is 0 spaces before the first character, then in the second row there is one space before a character, then in the third row there is 2 spaces before the character and so forth. Conversely, I am also decreasing the amount of characters printed in each line. But, the printing pattern stays the same character then space character then space until the max amount of char are hit... Hopefully, that helps... it should since I pretty much told you how to write the function is merely a matter of translating some bad English into code.
Wow, thanks! I got it working! thank you very much ats15 & kingkong200 !!
Topic archived. No new replies allowed.