Question: In C programming! I have the code I have so far attached at the bottom. Modify your program to prompt the user to input a

In C programming! I have the code I have so far attached at the bottom.

  • Modify your program to prompt the user to input a character for the shape (rather than *s).
  • Pass the input character (by value) to all of the functions.

Your program will need:

  • A new void function to print an inverted triangle called PrintInvertedTriangle
  • A modified prompt for the new shape:
    • i or I for an inverted triangle
      • then prompt for a base length (range 2 - 25)
      • if the base length is valid, call the PrintInvertedTriangle function
  • Modified function prototypes (changed from CE_6.1)
    • void PrintLine (int length, char theChar);
    • void PrintRectangle (int width, int height, char theChar);
    • void PrintTriangle (int baseLength, char theChar);
    • void PrintInvertedTriangle (int baseLength, char theChar);

NOTES:

  • You MUST build your solution on your CE_6.1 code. All previous test cases should still pass after adding the new function.
  • You MUST call PrintLine from within ALL other functions. If you don't, you won't pass a 2 point test case.
  • The user input length and width must be in the ranges specified for each shape. You must verify that the input is valid.
  • Any other letter should generate an error message.
  • Be sure to include your function prototypes before your main function, and your function definitions after your main function.

HINT: Remember to use " %c" when calling multiple scanf statements to input char data.

Sample output (sample input shown with underline):

Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 26 Length not in range.

Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle): i Which character: $ Enter an integer base length between 2 and 25: 7 $$$$$$$ $$$$$$ $$$$$ $$$$ $$$ $$ $

Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle): T Which character: $ Enter an integer base length between 3 and 25: 7 $ $$ $$$ $$$$ $$$$$ $$$$$$ $$$$$$$

Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle): x Which character: ? Unknown shape.

My code that needs to be modified:

#include #include

const int MAX_DIMENSION = 25;

//function prototypes void PrintLine(int length); void PrintTriangle(int baseLength); void PrintRectangle(int width, int height);

int main(void) { char option; int length,baseLength,width,height; //asking for user input printf("Which shape (L-line, T-triangle, R-rectangle): "); scanf("%c", &option); option = toupper(option); printf(" ");

//user input and checking to see if it is valid switch (option) { case 'L':printf("Enter an integer length between 1 and 25: "); scanf("%d",&length); if(length>=1 &&length<=MAX_DIMENSION) PrintLine(length); else printf("Length not in range."); break; case 'T':printf("Enter an integer base length between 3 and 25: "); scanf("%d",&baseLength); if(baseLength>=3 &&baseLength<=MAX_DIMENSION) PrintTriangle(baseLength); else printf("Length not in range."); break; case 'R':printf("Enter an integer width and height between 2 and 25: "); scanf("%d%d",&width, &height); if((width<2||width>MAX_DIMENSION)){ printf("Width not in range."); break; } if((height<2||height>MAX_DIMENSION)){ printf("Height not in range."); break; } if(width >= 2&&width<=MAX_DIMENSION && height>=2&&height<=MAX_DIMENSION) PrintRectangle(width, height); break; default: printf("Invalid option"); break; }

return 0; }

//printing results of user input void PrintLine(int length){ for(int i=0;i

printf(" "); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!