i think i'm familiar with it being hollow

#include <iostream>

using namespace std;

class Triangle
{
public:
  Triangle(int width, int height)
  : width(width), height(height / 2)
  {  }

  void draw()
  {
    int start_offset = width / 2;
    int end_offset = 0;
    for (int row = 0; row < height; ++ row) {
      int bgratio = (end_offset - start_offset) * row / height + start_offset;
      lineOf(' ', bgratio - 1);
      cout << '*';
      lineOf(' ', width - bgratio * 2);
      cout << ' *' << endl;
    }
  }

private:
  int width, height;

  void lineOf(char ch, int count)
  {
    for(; count; -- count)
      cout << ch;
  }
};

int main()
{
  Triangle triangle(16,16);
  triangle.draw();
}

Reply via email to