#include <iostream>
using std::cout;
using std::endl;
// include definition of class Triangles from Triangles.h
#include "Triangles.h"
// function to draw triangles
void Triangles::drawTriangles()
{
// Variable declarations (no other variables are needed)
int row; // the row position
int column; // the column position
int space; // number of spaces to print
// first triangle
for (int column = 0; column <=10; column++)
{
for (int column = 0; column <= row; row++)
{
cout << "*";
}
cout << endl;
} // end for;
// second triangle
for (int row=10; row >= 1; row++)
{
for ( int column=1; column <=row-1; column++)
{
cout << "*";
}
cout << endl;
} // end for;
// third triangle
for (int row = 9; row < 10; row++)
{
for (int space = 0; column <= row -1; column++)
{
cout << "*";
}
{
cout << " ";
}
cout << endl;
} //end for;
// fourth triangle
for (int row = 10; space <= row -1; row++)
{
for (int space = 9; space <= row - 1; row++)
{
cout << " ";
}
{
for (int column=10; column>= row; row++);
}
{
cout << "*";
}
{
cout << endl;
}
} // end for;
exit(0); // function ends successfully
} // end function drawTriangles
I didn't look over this fully, but you need to take a close look at your loops:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int row; // the row position
int column; // the column position <---------------- HERE
int space; // number of spaces to print
// first triangle
for (int column = 0; column <=10; column++) // <---------------- HERE
{
for (int column = 0; column <= row; row++) // <--------------- HERE AGAIN
{
cout << "*";
}
cout << endl;
} // end for;
Every time you do "int column" you're creating a new variable named column. Note that you're creating three separate variables named "column" in the above code. This probably was not your intent. Since you're declaring all of your variables up front at the top of your function, don't put them in every for loop:
1 2 3
int column;
for(column = 0; ... ) // <--- notice, just "column = 0", not "int colunn = 0"
Also, on the HERE AGAIN line, you're doing the following:
for (int column = 0; column <= row; row++)
it looks like you're counting column, but you're actually counting row. You probably meant to be counting row? I'm not exactly sure what it is you're trying to do here, but this wouldn't work.