I need to add a call to the PrintLine function of this code:
I need to add a call to the PrintLine function of this code:
#include <stdio.h>
//function prototypes
void PrintLine(int length, char theChar);
void PrintRectangle(int width, int height, char theChar);
void PrintTriangle(int baseLength, char theChar);
void PrintInvertedTriangle(int height, char theChar);
void PrintPyramid(int height, char theChar);
int main(void)
{
char choice;
int a, b;
char character;
//asking for user input
printf("Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle, P-pyramid): \n");
scanf(" %c", &choice);
printf("Which character: \n");
scanf(" %c", &character);
switch (choice)
{
//if user input is for a triangle
case 'T':
case 't':
printf("Enter an integer base length between 3 and 25: \n");
scanf("%d", &a);
if (a >= 3 && a <= 25)
PrintTriangle(a, character);
else
printf("Length not in range.");
break;
//if user input is for a rectangle
case 'R':
case 'r':
printf("Enter an integer width and height between 2 and 25: \n");
scanf("%d%d",&a, &b);
if((a<2 || a>25 )){
printf("Width not in range.");
break;
}
if((b<2||b>25)){
printf("Height not in range.");
break;
}
if(a >= 2&&a<=25 && b>=2&&b<=25)
PrintRectangle(a, b, character);
break;
//if user input is a line
case 'L':
case 'l':
printf("Enter an integer length between 1 and 25: \n");
scanf("%d", &a);
if (a >= 1 && a <= 25)
PrintLine(a, character);
else
printf("Length not in range.");
break;
//if user input is an inverted triangle
case 'i':
case 'I':
printf("Enter an integer base length between 2 and 25: \n");
scanf("%d", &a);
if (a >= 2 && a <= 25)
PrintInvertedTriangle(a, character);
else
printf("Height not in range.");
break;
//if user input is a pyramid
case 'P':
case 'p':
printf("Enter an integer width between 2 and 25: \n");
scanf("%d", &a);
if (a >= 2 && a <= 25)
PrintPyramid(a, character);
else
printf("Width not in range.\n");
break;
//if user input isn't a line, rectagnle, triangle, inverted triangle, or pyramid
default:
printf("Unknown shape.\n");
break;
}
}
//line function
void PrintLine(int length, char theChar)
{
int i;
for (i = 0; i < length; i++)
printf("%c", theChar);
printf("\n");
}
//triangle function
void PrintTriangle(int baseLength, char theChar)
{
int i, j;
for (i = 1; i <= baseLength; i++)
{
for (j = 0; j < i; j++)
printf("%c", theChar);
printf("\n");
}
}
//rectangle function
void PrintRectangle(int width, int height, char theChar)
{
int i, j;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
printf("%c", theChar);
printf("\n");
}
}
//inverted triangle function
void PrintInvertedTriangle(int height, char theChar)
{
int i;
for (i = height; i > 0; i--)
{
PrintLine(i, theChar);
}
}
//pyramid function
void PrintPyramid(int width, char theChar)
{
PrintTriangle(width, theChar);
PrintInvertedTriangle(width-1, theChar);
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images