ascii graph C help

correcting code

Page 1 of 1

0 Replies - 1922 Views - Last Post: 16 January 2008 - 07:51 PM Rate Topic: -----

#1 antlu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-January 08

ascii graph C help

Post icon  Posted 16 January 2008 - 07:51 PM

Given two points of a line, we should be able to graph a line connecting those two.
Given the Y endpoint and a directrix, we should be able to graph the arc with the formula y^2=4ax.
only the 1st quadrant should be graphed.
the origin must be at the upperleft most part of the screen.
we should be able to graph this by using ascii

please check my code.
i got a problem when the slope of the line not equal to 1.

we should also be able to ignore all other characters in the input except the numbers(ofcourse
ex
12sda34

another question, how could i clear the screen using system(); and not like what i did using only "\n"
sorry, my code is a mess... hope you'll understand... im just a beginner..

#include<stdio.h>
#define xlim 80
#define ylim 20
void system(void)
{
int c;
for(c=0;c!=20;c++)
	printf("\n");
}
int main(void)
{
int ym, yi, xval, dx, dy, c, v, xf, xl1, xl2, yl1, yl2, cx, cy, m, cb, y, b, ca, yf, xz, ma;
char a,s,d,f;

printf("line or arc?\n");
scanf("%c%c%c%c",&a,&s,&d,&f);

if ((a=='a')&&(s=='r')&&(d=='c'))
{
	printf("\nEnter Y endpoint; ");
	scanf("%d",&ym);
		if ((ym>ylim)||(y<0))
			printf("\nInvalid");
		else
	printf("\nEnter the value of the directrix: ");
	scanf("%d",&dx);
	system();
	for(yi=1;yi<=ym;yi++)
	{c=4;
	dy=yi*yi;
	v=c*dx;
	xf=dy/v;
	for(xval=0;xval<xf;xval++)
	{	printf(" ");
	}printf("0\n");
	}
}else if ((a=='l')&&(s=='i')&&(d=='n')&&(f=='e'))
{
	printf("\nEnter 1st X endpoint: ");
	scanf("%d",&xl1);
		if ((xl1>xlim)||(xl1<0)){
			printf("\nInvalid");
			return 0;
		}else
	printf("\nEnter 1st Y endpoint: ");
	scanf("%d",&yl1);
		if ((yl1>ylim)||(yl1<0)){
			printf("\nInvalid");
		return 0;
		}else
	printf("\nEnter 2nd X endpoint: ");
	scanf("%d",&xl2);
		if ((xl2>xlim)||(xl2<0)){
			printf("\nInvalid");
		return 0;
		}else
	printf("\nEnter 2nd Y endpoint: ");
	scanf("%d",&yl2);
		if ((yl2>ylim)||(yl2<0)){
			printf("\nInvalid");
		return 0;
		}else
	cx=xl2-xl1;
	cy=yl2-yl1;
	m=cy/cx;
	cb=m*xl1;
	b=yl1-cb;
	system();
	if (cx==0)
	{
		for(yf==1;yf<=ylim;yf++)
		{
			for(xf=1;xf<xl1;xf++)
			{
				printf(" ");
			}
			printf("0\n");
		}
	}else if (cy==0)
	{
		for(yf==1;yf<=yl1;yf++)
		{
			printf("\n");
		}
		for(xf==1;xf<=xlim;xf++)
		{
			printf("0");
		}
		for(yf==yf;yf<=ylim;yf++)
		{
			printf("\n");
		}
	}else if (yl1>yl2)
	{
		for(yf==yl2;yf<=yl1;yf++)
		{
			ca=yf-b;
			xf=ca/m;
			for(xz=0;xz<xf;xz++)
			{	printf(" ");
			}printf("0\n");
		}
	}else{
	
		for(yf==yl1;yf<=yl2;yf++)
		{
			ca=yf-b;
			xf=ca/m;
			for(xz=0;xz<xf;xz++)
			{	printf(" ");
			}printf("0\n");
		}
	}
}else{
	printf("\nInvalid");
	return 0;
}
printf("Is this ok?");
scanf("%c",&ma);
return 0;
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1