C++で二次式ソルバーを作成するこの課題を作業していますが、大部分はすべてが得られていると思いますが、 :二次式ソルバーの作成 - スコープ内で宣言されていない変数
main.cppに:54:11:エラー: '' この範囲
で宣言された。しかし、私はequSolver内のすべての変数(のために、このエラーが表示されていなかった)とoutResults()
#include <iostream>
#include <cmath>
using namespace std;
void findCoeff();
void equSolver(double a, double b, double c, double d);
double discr(double a, double b, double c);
void outResults(double root1, double root2, double a, double b, double c, double d);
void findCoeff(){
double a;
double b;
double c;
cout << "\nEnter coefficient a:\n";
cin >> a;
cout << "\nEnter coefficient b:\n";
cin >> b;
cout << "\nEnter coefficient c:\n";
cin >> c;
}
double discr(double a, double b, double c){
double d;
d = pow(b, 2) - (4 * a * c);
return d;
}
void equSolver(double a, double b, double c, double d){
double root1 = ((-1 * b) + sqrt(d))/(2 * a);
double root2 = ((-1 * b) - sqrt(d))/(2 * a);
}
void outResults(double root1, double root2, double a, double b, double c, double d){
if(std::isnan(root1) || std::isnan(root2)){
cout << "Quadratic equation with the following coefficients: \n";
cout << "a: " << a << "; b: " << b << "; c: " << c << "\n";
cout << "has no roots in the real domain\n";
}
else {
cout << "Quadratic equation with the following coefficients: \n";
cout << "a: " << a << "; b:" << b << "; c:" << "\n";
cout << "has the following roots\n";
cout << "Root1: " << root1 << "; Root2: " << root2 << "\n";
}
}
int main(){
findCoeff();
equSolver(a, b, c, d);
outResults(root1, root2, a, b, c, d);
}
私は、メインまたは変数としてdelcareを試みましたが、 yはすべて0に留まります。プログラムは実行されますが、計算は実際には行われません。
おかげ
あなたが 'equSolver(a、b、c、d);を実行するときに' main'で使うと期待されるのは 'a'、' b'、 'c'と' d'ですか? – NathanOliver
エラーメッセージはかなり明確です。それのどの部分を理解できないのですか? – IInspectable
findCoeff()からの入力です。 プログラムをコンパイルして実行することはできますが、変数が使用されていないときは実行します。 http://imgur.com/uI6DExF – Mathium