program must include the following:
ask the user for triangle size
triangle size must be between 1 and 20
it must ask the user if he wants to draw another triangle (Y or N)
ex:
enter triangle size: 25
size between 1 and 20, enter triangle size:5
*
**
* *
* *
*****
would you like to draw another triangle (Y or N): Y
enter triangle size: 3
and so on....
Code:
//This is my code
#include <iostream>
#include <iomanip>
using namespace std;
//main prgram
int main()
{
int t_s, //size of the triangle
col, //vertical line
line; //horizontal line
char ans; //Answer (Yes or No).
system("CLS");
cout << "Take Home #6 by Erick Aguilera - "
<< "The Draw Triangle\n\n";
do
{
cout << "Enter the triangle size: ";
// size of triangle
cin >> t_s;
while ((t_s < 1) || (t_s > 20))
{
cout << "Size must be between 1 and 20, "
<< "Enter the triangle size: ";
cin >> t_s;
}
for(col=1; col <= t_s; col++)
{ // add one '*' to line as many times as
// the value of col.
for(line=1; line<=col; line++)
{
cout << "*";
}
cout << " ";
cout << endl;
}
cout << "Would you like to draw another triangle "
<< "(Y or N): ";
cin >> ans;
}while (ans == 'Y');
cout << "End Program.\n";
return 0;
}