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

Trying to write a C program that prompts for a number between 1-79 and then 1-23

ID: 671335 • Letter: T

Question

Trying to write a C program that prompts for a number between 1-79 and then 1-23. If given an incompatible number or character, it must ask again until the requirements are met. Then using those two numbers, create a function called draw_box and have those two numbers draw a box. I'm having trouble trying to figure out how to draw the box.

Example output;

"Please enter the number of asterisks you want in your line: no

I'm sorry, that number is unrecognized or out of range, try [1-79]: 2

Please enter the number of lines you want in your box: -2

I'm sorry, that number is unrecognized or out of range, try [1-23]: 2

**

**

Press any key to continue..."

This is what i have so far:

#include

int main(int argc, char* argv[])

int i=1;

printf("Please enter the number of asterisks you want in your line: ")
       scanf("%d",&x);
       if(x>=1 && x<=79)
       {
           for( i=1;i<=x;i++)
               printf("*");
           break;
       }
       else
       {
           printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: ");
scanf("%d", x)

int i=1;

printf("Please enter the number of lines you want in your box:
       scanf("%d",&y);
       if(y>=1 && y<=79)
       {
           for( i=1;i<=y;i++)
               printf("*");
           break;
       }
       else
       {
           printf(" I'm sorry, that number is unrecognized or out of range, try [1-23]: ");

scanf("%d", &y);
    return 0;

Explanation / Answer

Hi, the first number you get use it as columns, e.g X

The second number you get use it as row e.g Y

Then in functibox draw_box()

Draw a matrix containing 'x'

int draw_box(int x,int y);

{

int i,j;

for(i=0;i<x;i++)

{

for(j=0;j<y;j++)

{

Printf("*");

}

}

return 0;

}

This draws a matrix which is also a box.Do let me know if you need a code for that.

If you don't want a full box of *'s , you can print only first and last column and first and last row.

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