whats wrong with my code?

Help. I am new to C++ and am trying to program that looks like this.
*
***
*****
*******
*********
*********
*******
*****
***
*
Cant seem to figure out whats wrong with my code. Help would be appreciated. Thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main(){
int i,j;
for (int i=1; i<=5; ++i)
{
        for (j=1; j<=i; j== i+2)
        {
                cout << "*";
        }
        cout << "\n";
}
for (int i = 6; i<=10; --i) {
        for (int j = 1; j<=i; j== i-2)
        {
        cout << "*";
        }
        cout << "\n";
        }
return 0;
}
line 5 those variables you only use j on line 8. Since line 6, 14, and 15 you create new variables.

As far as the pattern to me I see 1, 3 , 5, 7 , 9 and notice it increments by 2.
Then decrements by 2.

so that would mean you want to run the second loop i * 2 - 1 times.


which would mean it will look something like:
1
2
3
4
for(j = 0; j < i * 2 - 1; ++j)
{
   //stuff
}
also == is for comparrison and = is for assignment.
Topic archived. No new replies allowed.