Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void drawline(char sym, int num, int newline);
- void drawsquare(void);
- void drawtriangle(void);
- char askshape();
- int main()
- {
- char shape=0;
- printf("Welcome to the shape machine!");
- do {
- if(shape=='a'||shape=='A')
- drawsquare();
- else if(shape=='b'||shape=='B')
- drawtriangle();
- shape=askshape();
- } while(shape != 'c' && shape != 'C');
- printf("\nGoodbye!\n");
- return(0);
- }
- void drawline(char sym, int num, int newline)
- {
- int i;
- for(i=1;i<=num;i++)
- printf("%c", sym);
- if(newline)
- printf("\n");
- }
- void drawsquare(void)
- {
- int side, i, n;
- printf("What size is a side? ");
- scanf("%d", &side);
- drawline('x', side, 1);
- for(i=1; i<=side-2; i++)
- {
- printf("x");
- drawline(' ', side-2, 0);
- printf("x\n");
- }
- drawline('x', side, 1);
- }
- void drawtriangle(void)
- {
- int alt, base;
- int iii, ii, i; //counters
- int n, nn; //number of boxes (down)
- int w, l; //width and length of inner triangle
- int box0; //if there is an empty box at the bottom, how long it is
- char letter;
- printf("What is the altitude of the triangle? ");
- scanf("%d", &alt);
- printf("What is the base of the triangle? ");
- scanf("%d", &base);
- printf("What symbol should fill the triangle? ");
- scanf(" %c", &letter);
- if((base==2)||(alt==2))
- {
- drawline(letter, base, 1);
- alt--;
- for (i=1;i<=alt;i++)
- printf("%c\n", letter);
- }
- else if(base<alt)
- {
- w=base-2;
- l=alt-2;
- n=l/w;
- nn=n;
- box0=l%w;
- drawline(letter, base, 1);
- for(iii=1;iii<=nn;iii++)
- {
- for(ii=1;ii<=n;ii++)
- {
- printf("%c", letter);
- for(i=1;i<=w;i++)
- printf("%c", letter);
- printf("\n");
- }
- w--;
- }
- if(box0!=0)
- {
- for(i=1;i<=box0;i++)
- printf("%c\n", letter);
- }
- drawline(letter, 1, 1);
- }
- else if(alt<base)
- {
- w=alt-2;
- l=base-2;
- n=l/w;
- nn=n;
- box0=l%w;
- drawline(letter, base, 1);
- l-=box0;
- for(ii=1;ii<=nn;ii++)
- {
- printf("%c", letter);
- for(i=n;i<=l;i+=n)
- drawline(letter, n, 0);
- printf("\n");
- l-=n;
- }
- drawline(letter, 1, 1);
- }
- else
- {
- n=base;
- drawline(letter, base, 1);
- for(i=base;i!=0;i--)
- {
- n--;
- drawline(letter, n, 1);
- }
- }
- }
- char askshape()
- {
- char shape;
- printf("\n\nPick a shape:\nA) square\nB) triangle\nC) quit\n> ");
- scanf(" %c", &shape);
- return(shape);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement