I’m a beginning programmer and I’m a little bit stuck with this code. All I have to do is an asterisk pyramid like that:
*
**
***
****
*****
****
***
**
*
But when my pyramid starts to decrease, it stops with 4 asterisks and I have no more ideas to fix it. Hope someone could help me.
#include <iostream>
using namespace std;
int main(){
int i, j, x;
std::cin >> x;
for(i=1; i<=x; i++){
for(j=1; j<=i; j++){
std::cout << "*";
}
std::cout << "n";
}
for(i=x-1; i>0; i--){
for(j=1; j<x; j++){
std::cout << "*";
}
std::cout << "n";
}
return 0;
}
That’s what I got as a result:
*
**
***
****
*****
****
****
****
****
Source: Windows Questions C++