RedDucati748
MIS
I’m trying to create a program that will output a pyramid/triangle. The pyramid/triangle will use the character 'X' as found below in the both programs. The maximum height of the pyramid/triangle is 20 as found below in both programs. The first program creates a one sided pyramid/triangle, the second program outputs the correct height, but increments the spaces and characters incorrectly. I know that each level of the pyramid will increment the character count by two and I’m also aware that the number of spaces needed is one less then the height and then decreases by one space per line (Example: height equals 5; spaces on line 1 equals 4, character equals 1 - spaces on line 2 equals 3, character equals 3 and son on…). Can anyone help me with examples or suggestions for completing this task?
Thank-
Output should look like the following for height 5:
x
xxx
xxxxx
xxxxxxx
xxxxxxxxx
----------------------------------------------------------------------------------------------------------------------
include<iostream>
using namespace std;
int main()
{
int h, n, s, j;
do
{
cout<<"Enter pyramid height, must be fewer than 20 lines: ";
cin>>n;
}
while (n>24);
j=h;
cout<<"\n";
//j=h;
for(h=0; h<n; h++)
{
for(j=h; j>0; j--)
{
cout<<" ";
}
for(s=0; s<1; s++)
{
cout<<"X";
}
cout<<"\n";
}
cout<<"\n";
return 0;
}
---------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int h, n, s, j;
do
{
cout<<"Enter pyramid height, must be fewer than 20 lines: ";
cin>>n;
}
while (n>24);
j=h;
cout<<"\n";
//j=h;
for(h=0; h<n; h++)
{
for(j=0; j<34; j++)
{
cout<<" ";
}
for(s=0; s<1; s++)
{
cout<<"X";
}
cout<<"\n";
}
cout<<"\n";
return 0;
}
Thank-
Output should look like the following for height 5:
x
xxx
xxxxx
xxxxxxx
xxxxxxxxx
----------------------------------------------------------------------------------------------------------------------
include<iostream>
using namespace std;
int main()
{
int h, n, s, j;
do
{
cout<<"Enter pyramid height, must be fewer than 20 lines: ";
cin>>n;
}
while (n>24);
j=h;
cout<<"\n";
//j=h;
for(h=0; h<n; h++)
{
for(j=h; j>0; j--)
{
cout<<" ";
}
for(s=0; s<1; s++)
{
cout<<"X";
}
cout<<"\n";
}
cout<<"\n";
return 0;
}
---------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int h, n, s, j;
do
{
cout<<"Enter pyramid height, must be fewer than 20 lines: ";
cin>>n;
}
while (n>24);
j=h;
cout<<"\n";
//j=h;
for(h=0; h<n; h++)
{
for(j=0; j<34; j++)
{
cout<<" ";
}
for(s=0; s<1; s++)
{
cout<<"X";
}
cout<<"\n";
}
cout<<"\n";
return 0;
}