Please repair my loop.

#include <iostream>
using namespace std;

int main(){
   int size;
   cout << "How large a triangle do you want? ";
   cin >> size;

   for (int r = 0; r < size; r++) {
     for (int c = 1; c <= size; c++) {
        if (c <= r) cout << " ";
        else cout << "*";
     }
     cout << endl;
   }

   return 0;
}
instead the output is:
******
 *****
  ****
   ***
    **
     *

make it like this:
     *
    **
   ***
  ****
 *****
******

thanks in advance!!

You are on the right track. You just need to reverse how your loop goes. Look at your inner loop.

for (int c = 1; c <= size; c++)

If you reverse it from incremental loop value to decremental loop value with the range from (size-1) to 0 (inclusive), you should get the result you want.

Please repair my loop.

No, you repair it? What seems to be wrong? It's upside down, right? So reverse the code properly inside the outer loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.