Putting 2 points in to point-slope form

I am attempting to write a program that will allow you to enter 2 points and it will place them in to point-slope form. Unfortunately, I'm not competent enough.
Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <iostream>

using namespace std;

int main()
{
    float x1;
    float y1;
    float x2;
    float y2;
    float s=(y2-y1)/(x2-x1);
    cout << "Enter X of point A:" <<endl;
    cin >> x1;
    cout << "Enter Y of point A:" <<endl;
    cin >> y1;
    cout << "Enter X of point B:" <<endl;
    cin >> x2;
    cout << "Enter Y of point B:" <<endl;
    cin >> y2;
    cout << "When put in to point-slope form:" << (y2-y1)=(s*(x2-x1)) <<endl;
    return 0;
}



This is the error I am fetching:
error: invalid operands of types 'float' and '<unresolved overloaded function type>' to binary 'operator<<'|
Lines 7-10. You do create four variables, but do not set their values. They are uninitialized. Value unknown. That, in itself is not an error.

Line 11. You calculate something from unknown values and store the unknown result in new variable s. Value unknown. A logical error.

Lines 13-19 you do finally set the values of the four variables (unless input fails). They do now have defined values, but s remains unknown. You should move line 11 to after line 19.

Line 20.
(y2-y1) is an expression that evaluates to a value. Similarly, the (s*(x2-x1)) evaluates to a value.
Then you have assignment =
Would it make sense to write 3.14 = 4.2;? No. In assignment the value of the right side is stored into variable on the left side.

Your left side is not such a variable, or is it?

Both << and = are operators. Operators have precedence and order of evaluation.
For example:
1
2
3
4
5
6
7
8
9
10
cout << A << B;
// is same as
cout << A;
cout << B;

// but
A = B = C;
// is same as
B = C;
A = B;

Precedence says, which is evaluated first, << or =. That is where your error message is coming from.

The error points to syntax, but the real error is in the logic of the code.
What values do you want to calculate?
What values do you want to show?
Topic archived. No new replies allowed.