C++ nested while loop triangles

closed account (41U4izwU)
You might have seen this in the other forum, but i just wanted to see some other answers, since the ones that I have been receiving were not what I was hoping for...
I am trying to make triangles in nested while loops.

The triangles were:
*
**
***
****
*****
******
*******
********
*********
********** \\ I have made a code for this:

int counter=1;

while (counter<=10){

int counter2=1;

while (counter2<counter){

cout<<"*";

counter2=counter2+1;

}



cout<<"*"<<"\n";

counter=counter+1;

}


**********
--*********
----********
------*******
--------******
----------*****
------------****
--------------***
----------------**
------------------*
I was not quite sure about this one.
Please provide me with the correct answer, I really appreciate it :)
Last edited on
Just reverse the method you have made to get the first triangle and replace the spaces with dashes. Give us what you have so far for triangle 2.
Last edited on
closed account (41U4izwU)
Hi, I used the dashes on purpose for a space effect because when I tried to type it in, it always set it up to the side. Also, i think it might be a little more complicated than just reversing it, if it was just reflected from the first triangle, the code would have been similar to:

int counter=10 ;

while (counter>=1) {

int counter2=1;

while (counter2 <counter){
cout<<"*";
counter2=counter2 +1;
}

cout<<"*"<<"\n";
counter=counter-1;

but because the triangle is reflected twice, it's a little more difficult for me.
Last edited on
closed account (41U4izwU)
I'm sorry if this seems like a very simple question, but this is my first year learning programming, so i really appreciate those who are taking their time to help me with this :)
Topic archived. No new replies allowed.