for(int i=1;i<=2;i++)
{
gradient=((pt[i+1].y=4*i-7)-(pt[i].y=4*i-7))/((pt[i+1].x=i*i+3)-(pt[i].x=i*i+3));
cout<<"The gradient of this 2 point is "<<gradient<<endl;
}
}
int main()
{
cg w;
POINT pt[N+1];
for(int i=1;i<=3;i++)
{
pt[i].x=i*i=3;pt[i].y=4*i-7;
}
w.Calculate(pt);
return 0;
}
is it complete enough to computate the gradient?
thanks.
This looks enough to cause confusion.
There's a lot going on in this line: gradient=((pt[i+1].y=4*i-7)-(pt[i].y=4*i-7))/((pt[i+1].x=i*i+3)-(pt[i].x=i*i+3));
I would recommend simplifying this code by breaking that up into multiple lines, it has no less than five separate assignments in there. But ultimately I think it calculates gradient = 0 / 0; which is clearly wrong.
This line is also too complex: pt[i].x=i*i=3;pt[i].y=4*i-7;
Adding a bit of spacing we see this:
1 2
pt[i].x = i*i = 3;
pt[i].y = 4*i-7;
But this expression isn't valid: i*i = 3
Again, break up the code into multiple lines, keep things simple.