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;
}
}
}
|