Trying to write a C program that prompts for a number between 1-79 and then 1-23
ID: 671339 • 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..."
My code isn't compiling correctly and I don't have a clue as to why.
This is what i have so far:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void clear_keyboard_buffer(void);
void draw_box(int);
int main(int argc, char* argv[])
{
int x;
printf("Please enter the number of asterisks you want in your line: ");
scanf("%d", &x);
while (x < 1 || x > 79)
{
clear_keyboard_buffer();
printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: ");
scanf("%d", &x);
{
printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: ");
scanf("%d", &x);
{
int y = 0;
printf("Please enter the number of lines you want in your box: ");
scanf("%d", &y);
if (y >= 1 && y <= 23)
{
for (i = 1; i <= y; i++);
printf("*");
}
else
{
printf(" I'm sorry, that number is unrecognized or out of range, try [1-23]: ");
scanf("%d", &y);
return 0;
}
draw_box();
}
}
}
void clear_keyboard_buffer(void);
{
char ch;
scanf("%c", &ch);
while (ch != ' ')
{
scanf("%c", &ch);
}
}
void draw_box(int x, int y);
{
int i, j;
for (i = 0; i<x; i++)
{
for (j = 0; j<y; j++)
{
printf("*");
}
}
return 0;
}
Explanation / Answer
This is working perfectly for me.. Please clear the cach and temp of your system and please run again.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<conio.h>
void clear_keyboard_buffer(void);
void draw_box(int);
int main(int argc, char* argv[])
{
int x;
printf("Please enter the number of asterisks you want in your line: ");
scanf("%d", &x);
while (x < 1 || x > 79)
{
clear_keyboard_buffer();
printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: ");
scanf("%d", &x);
{
printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: ");
scanf("%d", &x);
{
int y;
printf("Please enter the number of lines you want in your box: ");
scanf("%d", &y);
}
if (y >= 1 && y <= 23)
{
for (i = 1; i <= y; i++);
printf("*");
}
else
{
printf(" I'm sorry, that number is unrecognized or out of range, try [1-23]: ");
scanf("%d", &y);
return 0;
}
draw_box(int x; int y);
}
}
void clear_keyboard_buffer(void);
{
char ch;
scanf("%c", &ch);
while (ch != ' ')
{
scanf("%c", &ch);
}
}
void draw_box()
void draw_box(int x, int y)
{
int i, j;
for (i = 0; i<x; i++)
{
for (j = 0; j<y; j++)
{
printf("*");
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.