How to output an isosceles triangle composed of & using c++?


the user can type in the size range within 2 and 20, and the triangle orientation ( i.e. which direction the triangle is pointing to ), right, left, up or down. the last line of output ends with an endl

Ensure to use the correct number of spaces(s), endlines(e) and ampersands(&).
E.g., expected answer is this
&&&&&&&&&&&&&
_&&&&&&&&&&&
__&&&&&&&&&
___&&&&&&&
____&&&&&
_____&&&
______&

where those black lines are spacing. the spacing is on ONE side only, not two sides!
sample run 3: &e&&e&&&e&&&&e&&&e&&e&e
sample run 11: sss&ess&&es&&&e&&&&es&&&ess&&esss&e
- Remove any system("Pause") before submission.
- You are encouraged to use proper indentation and comments in your code.


Sample run is like:
Triangle size: 4
Triangle orientation [r, d, u, l]: r
&
&&
&&&
&&&&
&&&
&&
&
Last edited on
show us what youve made so far
How do you intend to do it?
actually i wanna use for loop or while loop to do it, but still failed.
i saw a similar question on the internet but it used char which i haven't learnt yet
can anyone show me how to use for or while loop to do the question? thanks a lot
We're not going to do the problem for you.
Show us what you have and we'll try and help if you have specific questions.

There are examples how how to use for and while loops here:
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Two potential sources of help have asked you to show what you've tried so far, and really they can't be of much help if they don't know where you are in your learning process.

For example, if you can't use "char," what can you do?

Most people on this forum could probably write a program that does what you want, but if someone just gave it to you , how would that help you learn?

As I've told some others on this forum, your problem description is your program, just in a different language. Your job is to translate it to a form the computer can execute:

1
2
3
4
5
6
7
8
9
10
11
12
13
//the user can type in the size range within 2 and 20

code here to accept an input between 2 and 20

//and the triangle orientation

code here to accept one of four choices (r,d,u,l):

//  now that you have the user's choices:
// you'll need to calculate how to change the number of spaces and &
// notice that in each line of the first example the number of spaces increases by 1 and the number of & decreases by 2
// in the second example there are no spaces, but the number of & //increases by 1 per line until it reaches 4, then decreases by 1.
// do a for() loop to create and display the spaces and & 


maybe this site will help you how loops work
http://mathbits.com/MathBits/CompSci/looping/for.htm
Topic archived. No new replies allowed.