G
gbvk
Hello,
i'm trying to implement "y=mx+c" into code to find the intercept of a
line.
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
void main ()
{
int Ax, Ay, Bx, By;
float Dx, Dy, Dist, Grad;
cout<<"Please enter the 'x' coordinate of the first point: "<<endl;
cin>>Ax;
cout<<"Please enter the 'y' coordinate of the first point: "<<endl;
cin>>Ay;
cout<<"Please enter the 'x' coordinate of the second point: "<<endl;
cin>>Bx;
cout<<"Please enter the 'y' coordinate of the second point: "<<endl;
cin>>By;
Dx=Ax-Bx;
Dy=Ay-By;
Grad= Dy/Dx;
cout<<"Gradient = "<<Grad<<endl;
}
is what i have so far to find "m".
Ex A(2,3) B(6,5)
As I understand the fomula would be;
y-Ay = Grad*(x-Ax)
substituing from A;
y-3=0.5*(x-2)
y-3=0.5x-1
y=0.5x+2
therefore "c" would be: 2
any idea on how i could code this?
G
i'm trying to implement "y=mx+c" into code to find the intercept of a
line.
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
void main ()
{
int Ax, Ay, Bx, By;
float Dx, Dy, Dist, Grad;
cout<<"Please enter the 'x' coordinate of the first point: "<<endl;
cin>>Ax;
cout<<"Please enter the 'y' coordinate of the first point: "<<endl;
cin>>Ay;
cout<<"Please enter the 'x' coordinate of the second point: "<<endl;
cin>>Bx;
cout<<"Please enter the 'y' coordinate of the second point: "<<endl;
cin>>By;
Dx=Ax-Bx;
Dy=Ay-By;
Grad= Dy/Dx;
cout<<"Gradient = "<<Grad<<endl;
}
is what i have so far to find "m".
Ex A(2,3) B(6,5)
As I understand the fomula would be;
y-Ay = Grad*(x-Ax)
substituing from A;
y-3=0.5*(x-2)
y-3=0.5x-1
y=0.5x+2
therefore "c" would be: 2
any idea on how i could code this?
G