How write a program to draw curvy towers as in the sample runs below



Enter the height per section: 7
Enter the number of sections: 4

*****
*******
*********
***********
***********
*********
*******
*****
*******
*********
***********
***********
*********
*******
*****
*******
*********
***********
***********
*********
*******
*****
*******
*********
***********
***********
*********
*******
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<string>
#include<iostream>
using namespace std;

int main(){
int t;
cin>>t;
int height;
cin>>height;
int printed = 0;
int print_out = 5;
for (int i=0; i<t; i++){
    while (printed<=height+1){
        cout<<string(print_out, '*');
        cout<<"\n";
        if (printed<height/2+1){
            print_out++;
        }
        else if (printed==height/2 || printed==height/2+1){
            print_out = print_out;
        }
        else if(printed>height/2+1){
            print_out--;
        }
        printed++;

    }
    print_out = 5;
    printed = 0;
}
}


If you've got any questions as to how this code works, just asks
Last edited on
Topic archived. No new replies allowed.