/*************************************************
Draw a triangle
Write a program that reads a number n from the
user and draws a triangle of height n on the
screen using *'s.
Write and use a function "writelots" that takes
a char c and an int k and writes k instances of c
to the screen. For example:
writelots('z',5);
would produce
zzzzz
*************************************************/
#include <iostream>
using namespace std;
void writelots(char,int);
int main()
{
// Get value n
int n;
cout << "Enter the height of the triangle: ";
cin >> n;
// Write triangle
for(int i = 1; i <= n; i++)
{ // Write ith row
writelots(' ',n-i);
writelots('*',2*i-1);
cout << endl;
}
return 0;
}
/***********************************
** writelots(c,n) writes c n times.
***********************************/
void writelots(char c,int k)
{
for(int i = 0; i < k; i++)
cout << c;
}