#include<iostream>
using namespace std;
int main() {
    int height, star{ 0 };
    cout << "Enter height of triangle";
    cin >> height;
    for(int i=1; i<=height; i++)
    {
        if(star<i)
        {
            cout << "*";
            ++star;
            continue;
        }
        cout << endl;
        star = 0;
    }
}
This is printing stars in a line I want to print one star in 1st line then 2 in second line and so forth.
Example:
*
**
***
****
Image:

You should be able to simply do this:
#include <iostream>
using namespace std;
int main()
{
    int height;
    cout << "Enter height of triangle";
    cin >> height;
    for(int i=1; i<=height; i++)
    {
        cout << string(i, '*') << endl;            
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With