I am trying to create the pyramid (with 4 rows) using while loops. I think I have the idea correct but it's not outputting the pyramid right. I think it has mostly to do with the bracket placement and wrong source coding for the left and right side spacing. The pyramid should look like below (THE SLASHES ARE SPACES):
///*
//***
/*****
*******
Psuedocode:
Prompt user to enter a number of rows
Input 4 rows
Declare character asterisk
Prompt user to input a character for the pyramid
Input asterisk character
First while loop: While the quantity of rows is less than or equal to 4, create a new row. For each iteration of the first loop, increment by 1
Second while loop: While initial quantity of rows plus 1 is less than or equal to 4, increase the space by 1 for each iteration of the second loop
Third while loop: While 2 times the initial quantity of rows minus one is less than or equal to 4, print an asterisk. For each iteration of the third loop, increment by 1
#include <iostream>
usingnamespace std;
int main()
{
cout << "Enter a number of rows:" << endl;
int rows = 4;
cin >> rows;
cout << "Enter a character to draw the pyramid with:" << endl;
char VIEW = '*';
cin >> VIEW;
//this section is for setting the rows
int i = 1;//the i(initial) value (and value to increment by) is 1
while (i <= rows)//while the most recent value of i is less than or equal to the amount of outputted rows
{
i++;//increment the most recent value of i by 1
//this section is for the spacing
int j = 1;//the j(initial) value (and value to increment by) is 1
while (j <= rows - i)//while the most recent value of j is less than or equal to the amount of outputted rows minus the most recent value of i
{
j++;//increment the most recent value of j by 1}
cout << " ";//output an empty space
//this section is for printing the characters
int k = 1;//the k(initial) value (and value to increment by) is 1
while (k <= (2 * i) - 1)//while k is less than or equal to 1 times the most recent value of i minus 1
{
k++;//increment the most recent value of k by 1}
cout << VIEW;// print character...
// go to new line...
cout << endl;
}
}
}
}