(if statements not working) Finds equation of two points but is failing to check if a third pt lies on line

Hey my program works fine when finding the equation of the line the first 2 points lie one, but prints nothing to the screen after the third point is entered. I think it may be the if statements; please help it would be much appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
int main() 

{

double x1, y1, x2, y2, x3, y3, m, b; 


	cout << "Enter the x y coordinates for point one (e.g. 0.5 1.7):";
	cin >> x1 >> y1;
	
	cout << "Enter the x y coordinates for point two: ";
	cin >> x2 >> y2; //Calculate slope and y-intercept
	                //slope = rise over run
	m = (y2 - y1)/(x2 - x1);

	//line equation is y = m*x + b, so rearrange to get y-intercept b = m*x - y( not 		true b = y- mx).
	//this is true for all points, so it must be true for x1 y1

	b = y1 -  m*x1; 
	cout << "Your two points lie on the line" <<"y = " << m <<"x + " << b << endl;	

	//get a third point from user
	cout << "Enter the x y coordinates for point three: ";
	cin >> x3 >> y3;
// where i think it stops working
	if( y3 = m*x3 + b )
{		cout << "Point three also lies on the line " <<"y = " << m <<"x + " << b; 
		//this will lie on the line if y3 = m*x3 + b

}

	else if ( y3 != m*x3 + b)
{		cout << "Point three does not lie on the line" <<" y = " << m <<"x + " << b;
 
}

return 0;

}
Last edited on
line 28 you are using assignment operator '=' instead of comparison '=='
wow that was stupid of me, thanks a lot!
Not stupid at all. Typos are part of life ;)
Topic archived. No new replies allowed.