Write a program that prints isosceles triangles using the character \'*\'. The n
ID: 3623288 • Letter: W
Question
Write a program that prints isosceles triangles using the character '*'. The number ofrows forming the triangle is determined by the user. For instance, an isosceles triangle with
five rows looks like:
*
***
*****
*******
*********
My failed code so far is this:
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int n; // Number of rows declared by the user
int i; // Counting variable for number of rows
char star('*'); // Character for triangle
char blank(' '); // Spaces for uniformity
cout << "Enter number of rows: "; // Prompt for entering rows
cin >> n;
// User must enter at least 2
while (n<2)
{
cout << "Number of rows must be at least 2 " << endl;
cout << "Enter number of rows: ";
cin >> n;
}
for (i=2; i<=n; i=i+1)
{
cout << setfill(blank) << setw(n) << blank;
cout << setfill(star) << setw(i*2-1) << star;
cout << blank << endl;
}
return(0);
}
Explanation / Answer
int main(int argc, char *argv[]) { int height = -1; while (height height; } int num_of_pluses = 1; for (int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.