Triangle task (hints please)

Write your question here.

Hi. I now face difficulties in a programming problem.
I am required to write the codes of a programme which can display a triangle made of &:

enter the size and orientation [r, d, u, l],
for instance, if I enter 3 and r, the result will give


&
&&
&&&
&&
&


if I enter 5 and l; the result will give

    
    &
   &&
  &&&
 &&&&
&&&&&
 &&&&
  &&&
   &&
    &


I know this programme is quite complicated. It requires skills of using switch and nested loops (for loop). I am quite confused about how to make it display 1 symbol in the first row, then 2 in the second, 3 in the third and so on... And I also want to know whether I need to do something before I write the switch cases code for the orientation?

I know many of you experts are so nice and may directly give me the answer...
But I hope I can do it by myself eventually, so can anybody give me some hints? Thank you!

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

#include<iostream>
using namespace std;

int main ()
{
    char orientation;
    char symbol = '&';
    int size_Triangle;

    cout << "Please enter the size of triangle: ";
    cin >> size_Triangle;

    cout << "\n Please also enter orientation [r, d, u, l]: ";
    cin >> orientation;

    int row = 0;
    int column = 0;

    switch (orientation)
    {
    case 'r':
        row = 1;
        for (count = size_Triangle; count > 1; count++)
        {
            row += 2;
        }

    }
    
}
Last edited on
closed account (48T7M4Gy)
What happens when you run it?
I just dont know how to write...
I'll stop at there
Last edited on
closed account (48T7M4Gy)
OK, when I run it there is an error on line 24 because you haven't declared that count is an integer.
that is a mistake
but that is not the main problem

the problem is how I can first give out 1 &, then 2 &, and then 3 & until it meets the size of the triangle?
closed account (48T7M4Gy)
try using a for loop? Maybe include a cout << '*'
How would you do **
Topic archived. No new replies allowed.