We were supposed too make a program that would connect the given 2 points of a line. My program has a problem if the slope of the line is not 1. I'm just a noob in programing
and still don't know how to clear the screen using system();

#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
	[B]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");
		}
	}[/B]
}else{
	printf("\nInvalid");
	return 0;
}
printf("Is this ok?");
scanf("%c",&ma);
return 0;
}

Recommended Answers

All 2 Replies

>> scanf("%c%c%c%c",&a,&s,&d,&f);
>> if ((a=='a')&&(s=='r')&&(d=='c'))
>> else if ((a=='l')&&(s=='i')&&(d=='n')&&(f=='e'))
I'm guessing you don't know about using character arrays then? Take a look here. Ones to note are strcmp() and look into scanf-fing with %s .

>> system();
What's that there for?

>> for(yf==yl1;yf<=yl2;yf++)
The first parameter in a for loop is meant to be assignment, not comparison, like here:
>> for(xf=1;xf<xl1;xf++)

I find it very difficult to read your code. Fair enough it's indented and such... but it's a little all over the shop...

tnx for the advice... i did get what i wanted... i'll just fix my code for passing... array helped a lot... thread closed..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.