Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will create a program that draws ASCII boxes. The user specifies the width a

ID: 3595551 • Letter: Y

Question

You will create a program that draws ASCII boxes. The user specifies the width and height of the box. At a minimum, the box has to be two characters wide by two characters tall, as the width and height values include the borders! For example, the smallest box, a two by two box, looks like this: That is, just the four corners A corner is represented using a plus sign (+'). The top and bottom borders are drawn with a dash (-). The sides are dra A width 5, height 3 box looks like this: wn with a pipe () and a width 3, height 5 box looks like this: Open the file box.c. All of the variables that you need are declared in the first two lines of the main) function. The input portion is done for you, but you will have to complete the input validation that follows If the width or the height are below the minimum acceptable value, then the program should print an error message and exit. Complete the code to print out the top line, followed by a nested loop to print out the middle portion, and then lastly create the code necessary to print out the bottom edge of the box.

Explanation / Answer

Implemented the code as per your requirement and added comments at some places for better readability. Thank you..

Code:

-----------

#include<stdio.h>
#include <stdlib.h>

int main(void) {
int i,j;
int height,width;

printf("Input box dimensions (width height) : ");
scanf("%d%d",&width, &height); //Taking the dimensions
printf(" ");

//Validating the dimensions
if(width<2){
exit(0);
}
if(height<2){
exit(0);
}

//First line
printf("+");
for(i=1;i<=width-2;i++){
printf("+");
}
printf("+ ");

//Middle lines
for(i=1;i<height-1;i++){
printf("|");
for(j=1;j<width-1;j++){
printf(" ");
}
printf("| ");
}

//Last line
printf("+");
for(i=1;i<=width-2;i++){
printf("+");
}
printf("+ ");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote