I am supposed to write a program that prompts the use for number of lines, then outputs ASCII art in a "V" shape. For input 4, output is ("-" represents spaces):
*-----* -*---* --*-* ---*
My code is:
// prompt for number of stars
int stars;
std::cin >> stars;
// indent
int indent = 0;
int space = 1;
// find space
if (stars = 1)
{
space = 0;
}
else if (stars == 2)
{
space = 1;
}
else if (stars >= 3)
{
int addspace = stars - 2;
space = space + (2 * addspace);
}
// print spaces to double check calculation
std::cout << "space: " << space << '\n';
// print first star
if (stars == 1)
{
std::cout << "*";
}
// print lines
for (int lines = 1; lines == stars; ++lines)
{
// print indent
std::cout << "indent: " << indent << '\n'
<< "spaces: " << space << '\n';
if (lines > 1)
{
for (int ind_loop = 1; ind_loop < indent; ++ind_loop)
{
std::cout << " ";
}
}
std::cout << "*";
indent += 1;
// print spaces
std::cout << "spaces: " << space << '\n';
for (int sp_loop = 0; sp_loop < space; ++sp_loop)
{
std::cout << " ";
}
space -= 2;
std::cout << "*";
// next line
std::cout << '\n';
}
std::cout << '\n';
Every time it gives me just:
*
and int spaces always comes out to equal 0.
Does anyone know why this might be, and what I need to do to correct it?