I had to do 2 changes in your code to make it work:
Replace all 10 with rowNum
Second outer loop should be
for (x = rowNum; x >= 1; x--) //outer loop
Note: It works fine only for an even number of rows. You will need to handle the case of an odd number of rows.
Updated code:
std::cout << " Enter the Numbers of rows you would like between 3 and 15: " << std::endl;
std::cin >> rowNum;
for (x = 1; x <= rowNum; x++) //outer loop
{
for (y = 1; y < x; y++) {
if (y <= (rowNum - x))
std::cout << " ";
else
std::cout << "*";
}
std::cout << std::endl;
}
for (x = rowNum; x >= 1; x--) //outer loop
{
for (y = 1; y < x; y++) {
if (y <= (rowNum - x))
std::cout << " ";
else
std::cout << "*";
}
std::cout << std::endl;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…