I know how to draw a square or a rectangle, but what's the code to draw a triangle? Does anyone have any idea.
Lin
This is a discussion on Drawing triangles within the C++ Programming forums, part of the General Programming Boards category; I know how to draw a square or a rectangle, but what's the code to draw a triangle? Does anyone ...
I know how to draw a square or a rectangle, but what's the code to draw a triangle? Does anyone have any idea.
Lin
what language, graphics library, OS, compiler?
C++
Something that would look like this
*
***
*****
******
with two variables, base and height...
thanks, Lin
I mean like this...
SorryCode:* *** **** *****
Lin
That's not it either...
I'm looking for something with the top in the middle of the base and the two sides angling down.
Lin
possibly something like this
Code:for (int numrows=1; numrows<height; numrows++) { for (int c=1; c<=base; c++) { if (c < ((base/2)-(c-1)) || c > ((base/2)+(c-1)) { cout << " "; } else { cout << "*"; } } }
let me guess your using a book by lawrenceville press
Code:#include <iostream.h> //------------------------------------------------------------------------------ void Spaces(int spaces) /* Set leading spaces before the '*' */ { for(int count=0; count<=spaces; count++) { cout<<" "; } } //------------------------------------------------------------------------------ void DrawBar(int sizeofrow,int spaces) /* Display a bar of '*' of a set increasing lenght */ { Spaces(spaces); for(int count=0; count<sizeofrow; count++) { cout<<"*"; } cout<<endl; } //------------------------------------------------------------------------------ void Isotriangle(int columns) /* Build the triangle and set size of bars */ { int count=0; int sizeofrow=1; int stospaces; stospaces=columns; while(count!=columns) { count++; if (count>1) { sizeofrow=sizeofrow+2; } DrawBar(sizeofrow, stospaces); stospaces--; } } //------------------------------------------------------------------------------ int main() { int columns; cout<<"Enter the number of rows you want for your triangle: "; cin>>columns; Isotriangle(columns); cout<<endl; return (0); }