Pyramid asterisk using while and for loop structures in C++


#include <iostream>
using namespace std;
int main()
{
    int pyramid_height;
int line;
    int count;
           
    cout<<"Enter the Height of a pyramid: ";
    cin>>pyramid_height;
   
while(pyramid_height > 30 || pyramid_height < 1)
    {
        cout<<"Pick another height (must be between 1 and 30): ";
        cin>>pyramid_height;
    }
        cout<<endl;
    for (line = 1 ; line <= pyramid_height ; line++)
    {
        int total_no_of_spaces =  pyramid_height - line;
                 
        for (count = 1 ; count <= total_no_of_spaces ; count++)
            cout<<' ';
                           
            for (count = 1 ; count < line * 2 ; count++)
                cout<<'*';
                cout<<endl;
    }
    return 0;
}
 OUTPUT
Pyramid asterisk using while and for loop structures in C++ Pyramid asterisk using while and for loop structures in C++ Reviewed by code-dev on 9:00 PM Rating: 5

No comments:

Powered by Blogger.