- #1
jaydnul
- 558
- 15
I have to write a program that will take user input to make certain shapes. If the user inputs 's', its a solid square, 'b', its a hollow box, 't' its a triangle. They also choose how many rows it is and what the shape is made of. Example
****
****
****
this would be a user input of 's', 3 rows, and the * symbol.
Now the part i can't figure out is how to specify the rows. I would have just used if statements and make a shape out a bunch of %c but i can't figure out how to make it more or less rows by user input. This is my code so far:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char a,c;
int b;
printf("Enter \"s\" for a square\nEnter \"b\" for a box\nEnter \"t\" for a triangle\n");
scanf("%c",&a);
system("cls");
if (a=='s')
printf("Square\n--------------------…
if (a=='b')
printf("Box\n--------------------\n"…
if (a=='t')
printf("Triangle\n------------------…
printf("Enter the number of rows\n");
scanf("%d",&b);
system("cls");
if (a=='s')
printf("Square, %d rows\n--------------------\n",b);
if (a=='b')
printf("Box, %d rows\n--------------------\n",b);
if (a=='t')
printf("Triangle, %d rows\n--------------------\n",b);
printf("Enter the character to use for drawing\n");
scanf(" %c",&c);
system("cls");
if (a=='s')
printf("Square, %d rows, made of \"%c\" characters\n--------------------\n",b,c)…
if (a=='b')
printf("Box, %d rows, made of \"%c\" characters\n--------------------\n",b,c)…
if (a=='t')
printf("Triangle, %d rows, made of \"%c\" characters\n--------------------\n",b,c)…
/*Making the shape*/
}
And obviously i don't have anything under "making the shape". So far, my code asks for the 2 characters and 1 variable i need from the user but i don't know how to go about the rest.
Any help? thanks in advance
****
****
****
this would be a user input of 's', 3 rows, and the * symbol.
Now the part i can't figure out is how to specify the rows. I would have just used if statements and make a shape out a bunch of %c but i can't figure out how to make it more or less rows by user input. This is my code so far:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char a,c;
int b;
printf("Enter \"s\" for a square\nEnter \"b\" for a box\nEnter \"t\" for a triangle\n");
scanf("%c",&a);
system("cls");
if (a=='s')
printf("Square\n--------------------…
if (a=='b')
printf("Box\n--------------------\n"…
if (a=='t')
printf("Triangle\n------------------…
printf("Enter the number of rows\n");
scanf("%d",&b);
system("cls");
if (a=='s')
printf("Square, %d rows\n--------------------\n",b);
if (a=='b')
printf("Box, %d rows\n--------------------\n",b);
if (a=='t')
printf("Triangle, %d rows\n--------------------\n",b);
printf("Enter the character to use for drawing\n");
scanf(" %c",&c);
system("cls");
if (a=='s')
printf("Square, %d rows, made of \"%c\" characters\n--------------------\n",b,c)…
if (a=='b')
printf("Box, %d rows, made of \"%c\" characters\n--------------------\n",b,c)…
if (a=='t')
printf("Triangle, %d rows, made of \"%c\" characters\n--------------------\n",b,c)…
/*Making the shape*/
}
And obviously i don't have anything under "making the shape". So far, my code asks for the 2 characters and 1 variable i need from the user but i don't know how to go about the rest.
Any help? thanks in advance