C/C programming
Expert: Prince M. Premnath - 8/22/2006
QuestionI have been trying to make a box and put my time table in the box, but it is not working yet. What is wrong with my code? Please give me the way to solve it. Thank you for your time.
#include<stdio.h>
#include<conio.h>
#define size_of_box 40
main()
{
int time, number, answer, i, j;
//top line
printf("%c",201);
for (i=0; i<size_of_box; i++)
printf("%c", 205);
printf("%c", 187);
/*sides of box*/
for (i=0; i<size_of_box; i++)
{
printf("\n%c", 186);
printf(" Enter number between 1 and 12: ");
scanf("%d",&time);
printf("\n%8d times multiplication table\n", time);
for(number=1; number<=12; number++)
{
answer=number*time;
printf("\n%16d x %d = %d", number,time, answer);
}
for (j=0; j<size_of_box; j++)
printf(" ");
printf("%c",186);
}
//bottom line
printf("\n%c", 200);
for (i=0; i<size_of_box; i++)
printf("%c", 205);
printf("%c",188);
getch();
return(0);
}
Answer Nothing wrong with your program , but your program organization is little bit wrong;
1 - Draw the box the write the data into the box,
2 - Write the data first then put the box
3 - If you wish to do the both jobs simultaneously CARE should be taken
You did it almost right but you forgot to write code to draw side grids
Here i give you my code i think possibly it will help you !
#include<stdio.h>
#include<conio.h>
void box( int xmin , int ymin , int xmax , int ymax)
{
int i , j;
gotoxy(xmin , ymin);
putchar(201);
gotoxy(xmax , ymin);
putchar(187);
gotoxy(xmin , ymax);
putchar(200);
gotoxy(xmax , ymax);
putchar(188);
for( i = xmin + 1 ; i <= xmax - 1; i++)
{
j = ymin;
gotoxy(i , j);
putchar(205);
//printf("Í");
gotoxy(i , j + ( ymax - ymin ) );
putchar(205);
//printf("Í");
}
for( i = ymin + 1 ; i <= ymax - 1 ; i++)
{
j = xmin;
gotoxy( j , i );
putchar(186);
gotoxy(j+(xmax - xmin) , i);
putchar(186);
}
}
void main()
{
int time, number, answer, i, j;
clrscr();
printf("Enter the number between 1 and 12:");
scanf("%d" , &time);
clrscr();
for(number=1; number<=12; number++)
{
answer=number*time;
printf("\n%16d x %d = %d", number,time,answer);
}
box(1 , 1 , 40 , 15);
getch();
}
Note :
In short time i prepared this code ;
Thank you ! _ Happy Programming