Rectangle with "*"

Hi,
I am supposed to make a program in which you give 2 numbers and those 2 numbers should be the width and height of a triangle made with "*". If I cin 3 and 5 I get:
**
*
*
**
*
*
**
*
*
**
*
*
**
*
*
While I should get:
***
***
***
***
***
Can anyone explain this to me?
Here is my code:
#include <iostream>
using namespace std;
int main(int argc, char **argv) {



int Height, Width, i, j;
cin >> Height;
cin >> Width;





for (int i = 0; i< Width; i++) {

cout << "*" ;

for(int j = 0; j < Height; j++)
{
cout << "*";
cout << endl;
}
}
}
Last edited on
Switch for loops for width and hight and delite >cout << "*" ;< between for loops and >cout << endl;< should be outside the inner for loop.
That should fix your problem.
Last edited on
Thanks it worked
Topic archived. No new replies allowed.