Back to General discussions forum
//solve find a and b in y = ax + b given two points
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
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.