Help linear function

Back to General discussions forum

ezra.jesalva15     2016-11-30 18:37:39

//solve find a and b in y = ax + b given two points

include<iostream>

using namespace std;

int main() { int numLines = 0; cin >> numLines;

for(int i = 0; i < numLines; i++) //stops after all lines done
{
    int a = 0, b = 0;
    int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    cin >> x1;
    cin >> y1;
    cin >> x2;
    cin >> y2;

    a = (y2-y1) / (x2-x1);
    b = y1 - (a * x1);

    cout <<"(" << a << " " << b << ") ";

}


return 0;

}

Why doesn't this work? When I put it in nothing appears

Quandray     2016-11-30 21:20:30
User avatar

It looks like running C/C++ code by pressing the C/C++ button, no longer puts the result in the "Your answer" box. That's annoying!

I can only suggest that you run the code somewhere else, then copy/paste the answer into the "Your answer" box.

Please login and solve 5 problems to be able to post at forum