こんにちは、宿題のソリューションコードを書くのに苦労しています。2つの方程式に6つの変数を入力するようにユーザーに依頼する必要があります。数値のみを正常に取得した後、解決策がある場合は、各線の傾き、各線のy切片、各線の2つの点((2,1)などの順序対)を見つける必要があります。また、関係は何ですか。私は主に数のチェックと方程式を検索して検索しました。私が問題を抱えているのは、方程式のポイントと解を見つけることです。
#include <iostream>
#include <limits>
int main()
{
std::cout<<"This program is designed to test two linear equations. \n";
std::cout<<"In order to best solve the system, \n";
std::cout<<"equations will be in the form of a*x + b*y = c. \n";
std::cout<<"and d*x + e*y =f. \n";
std::cout<<"Please enter an integer for a, b, and c. \n";
double a, b, c, d, e, f;
while ((std::cout << "Enter a.")
&& !(std::cin >> a))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter b.")
&& !(std::cin >> b))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter c.")
&& !(std::cin >> c))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout<<"Equation 1 is "<<a<<"x +"<<b<<"y ="<<c;
std::cout<<"Please enter an integer for d, e, and f. \n";
while ((std::cout << "Enter d.")
&& !(std::cin >> d))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter e.")
&& !(std::cin >> e))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter f.")
&& !(std::cin >> f))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout<<"Equation 2 is "<<d<<"x +"<<e<<"y ="<<f;
double slope1, slope2;
double x1, x2, y1, y2;
slope1 = (b / a);
slope2 = (e / d);
std::cout<<" Slope of Equation 1 is "<<slope1<<"\n";
std::cout<<" Slope of Equation 2 is "<<slope2<<"\n";
x1 = ((c*e)-(b*f))/ ((a*e)-(b*d));
y1 = ((a*f)-(c*d))/ ((a*e)-(b*d));
return 0;
}