Should look like this ********** ********* ******** ******* <- straight like a t
ID: 3643445 • Letter: S
Question
Should look like this**********
*********
********
******* <- straight like a triangle
******
*****
****
***
**
*
Code:
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int row = 0;
int star = 0;
int space = 0;
//Star pattern
do
{
for (space = -1; space <= 10 - star; space++)
{
cout << " ";
}
for (star = 1; star <= 11 - row; star++)
{
cout << "*";
}
cout << endl;
row++;
}
while (row <= 10);
system("pause");
return 0;
}
But I get this goofy piece right before the pattern.
Please help.
Explanation / Answer
It's because you are using one variable (star) to do two different things.
Use the following code, and the triangle will be shown correctly:
///////////////////////
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int row = 0;
int star = 12;
int space = 0;
//Star pattern
do
{
for (space = -1; space <= 10 - star; space++)
{
cout << " ";
}
for (int i = 1; i <= 11 - row; i++)
{
cout << "*";
}
cout << endl;
row++;
star--;
}
while (row <= 10);
system("pause");
return 0;
}