hi guys,
I am working on a calculation for a homework assignment, and I am pretty new in C++. So sorry if the question seems silly. I am working on a calculation for slope intercept form (here's a refresher on it: https://www.studypug.com/algebra-help/linear-functions/linear-function-slope-intercept-form
So when I compile and work on the code, it dies, my last line seems to croak with invalid operands. I must've done something wrong in the cout operation.
float y1, y2, m, x1, x2, b;
char X, Y;
// enter the X and Y for the calculation
cout<<"Please Enter the first X: ";
cin>> x1;
cout<<"Now Enter the first Y: ";
cin>> y1;
cout<<"Please Enter the second X: ";
cin>> x2;
cout<<"Now Enter the second Y: ";
cin>> y2;
//slope calculation
m=(y2-y1)/(x2-x1);
cout<<"Great, The slope is: "<< m <<"\n";
cin.get();
///get the final slope intercept form
b=y1-(m*x1);
cout<<"Now, the y intercept is: "<< b <<"\n";
cout<<''And the final line equation is: "<< y=m*x+b <<"\n";
#include <iostream>
#include <iomanip>
int main()
{
double x1 = 0, y1 = 0, x2= 0, y2 = 0 ;
// enter the X and Y for the calculation
std::cout << "Please Enter the first X: ";
std::cin >> x1;
std::cout << "Now Enter the first Y: ";
std::cin >> y1;
std::cout << "Please Enter the second X: ";
std::cin >> x2;
std::cout << "Now Enter the second Y: ";
std::cin >> y2;
// slope calculation
constdouble m = (y2-y1) / (x2-x1) ;
std::cout << "\nGreat, The slope is: " << m << '\n' ;
// get the final slope intercept form
constdouble b = y1 - (m*x1) ;
std::cout << "Now, the y intercept is: " << b << '\n' ;
// line equation eg. y = 2.6 * x + -4.2
std::cout << "And the final line equation is: "
<< "y = " << m << " * x + " << b << '\n';
}
shoot.. thanks! That explains why my output wasn't working! Okay, so now everything works and I am getting the result from my slope intercept form.
greatly appreciated!