I\'m stuck on a program to print an isosceles triangle. What I have so far isn\'
ID: 3651892 • Letter: I
Question
I'm stuck on a program to print an isosceles triangle. What I have so far isn't printing a triangle, just a straight column of numbers. Please help.//File: triangles.cpp
//Created By:
//Created On: 10/3/2012
/*
*/
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int rows;
int j;
int i;
int k;
cout << "Number of rows: ";
cin >> rows;
//error for integer <2 and prompt for reentry
while(rows <= 1 )
{
cerr << "Number of rows must be at least two."<< endl;
cout << "Enter number of rows: ";
cin >> rows;
}
for(int i=1;i<=rows;i++)
{
for(int j=1;j<=rows-i;j++)
{
cout << " ";
for(int k=1;k<=2*i-1;k++)
{
cout << "*";
cout <<" ";
}
}
}
return 0;
}