&引用;预期不合格id“;就这么说 >我试图为C++中的编程类编写代码。我们目前正在尝试使用牛顿-拉斐逊方法来寻找三次多项式的3个根。我收到一个错误,上面写着“预期的非限定id”。这就是它所说的一切。在这个框架下,计算机将胡萝卜放在支架下。我已经为这个错误挣扎了一段时间,所以任何建议都将是惊人的!我将在下面发布代码 #include <iostream> #include <cmath> using namespace std; double nrmethod(int r1, double fr1, double dr1fr1, int imax, double es); int main () { int sxx=10, sxy=14, sxz=25, syy=7, syz=15, szz=16;/* declaring integers to calculate the coefficients of the algebraic equation. this algebraic equations roots are the values we are looking for*/ int I; int II; int III;/*delcaring the coefficents of the algebraic equation*/ I=sxx+syy+szz; II=(sxx*syy)+(sxx*szz)+(syy*szz)-(pow(sxy,2))-(pow(sxz,2))-(pow(syz,2)); III=(sxx*syy*szz)-(sxx*pow(syz,2))-(syy*pow(sxz,2))-(szz*pow(sxy,2))+(2*sxy*sxz*syz);/*solving for the coefficents of the algebraic equation*/ cout << I << ", " << II << ", " << III << endl; /*displaying the coefficients of the algebraic equation*/ int imax=100; double es=0.01; double dr1fr1; double fr1; int r1; cout <<"enter guess for the root"; cin >> r1; double r = nrmethod(r1, fr1, dr1fr1, imax, es); cout << r << std::endl; return 0; } double nrmethod(int r1, double fr1, double dr1fr1, int imax, double es);{ double fr1=pow(r1,3)-I*pow(r1,2)+(II*r1-III); double dr1fr1= 3*pow(r1,2)-(2*I*r1)+II; do int k=1; if(k<= imax){ k++; r2=r1-(fr1/dr1fr1); if r2 !=0 then int er=(abs(r2-r1)/abs(r2))*100; if(er<es){end do} else {return r2} } cout << r2; return 0; } #包括 #包括 使用名称空间std; 双NR法(整数r1、整数fr1、整数dr1fr1、整数imax、整数es); int main() { int sxx=10,sxy=14,sxz=25,syy=7,syz=15,szz=16;/*声明整数以计算代数方程的系数。这些代数方程的根就是我们要寻找的值*/ int I; int II; int III;/*代数方程的系数*/ I=sxx+syy+szz; II=(sxx*syy)+(sxx*szz)+(syy*szz)-(pow(sxy,2))-(pow(sxz,2))-(pow(syz,2)); III=(sxx*syy*szz)-(sxx*pow(syz,2))-(syy*pow(szz,2))-(szz*pow(sxy,2))+(2*sxy*szz*syz);/*代数方程系数的求解*/ cout

&引用;预期不合格id“;就这么说 >我试图为C++中的编程类编写代码。我们目前正在尝试使用牛顿-拉斐逊方法来寻找三次多项式的3个根。我收到一个错误,上面写着“预期的非限定id”。这就是它所说的一切。在这个框架下,计算机将胡萝卜放在支架下。我已经为这个错误挣扎了一段时间,所以任何建议都将是惊人的!我将在下面发布代码 #include <iostream> #include <cmath> using namespace std; double nrmethod(int r1, double fr1, double dr1fr1, int imax, double es); int main () { int sxx=10, sxy=14, sxz=25, syy=7, syz=15, szz=16;/* declaring integers to calculate the coefficients of the algebraic equation. this algebraic equations roots are the values we are looking for*/ int I; int II; int III;/*delcaring the coefficents of the algebraic equation*/ I=sxx+syy+szz; II=(sxx*syy)+(sxx*szz)+(syy*szz)-(pow(sxy,2))-(pow(sxz,2))-(pow(syz,2)); III=(sxx*syy*szz)-(sxx*pow(syz,2))-(syy*pow(sxz,2))-(szz*pow(sxy,2))+(2*sxy*sxz*syz);/*solving for the coefficents of the algebraic equation*/ cout << I << ", " << II << ", " << III << endl; /*displaying the coefficients of the algebraic equation*/ int imax=100; double es=0.01; double dr1fr1; double fr1; int r1; cout <<"enter guess for the root"; cin >> r1; double r = nrmethod(r1, fr1, dr1fr1, imax, es); cout << r << std::endl; return 0; } double nrmethod(int r1, double fr1, double dr1fr1, int imax, double es);{ double fr1=pow(r1,3)-I*pow(r1,2)+(II*r1-III); double dr1fr1= 3*pow(r1,2)-(2*I*r1)+II; do int k=1; if(k<= imax){ k++; r2=r1-(fr1/dr1fr1); if r2 !=0 then int er=(abs(r2-r1)/abs(r2))*100; if(er<es){end do} else {return r2} } cout << r2; return 0; } #包括 #包括 使用名称空间std; 双NR法(整数r1、整数fr1、整数dr1fr1、整数imax、整数es); int main() { int sxx=10,sxy=14,sxz=25,syy=7,syz=15,szz=16;/*声明整数以计算代数方程的系数。这些代数方程的根就是我们要寻找的值*/ int I; int II; int III;/*代数方程的系数*/ I=sxx+syy+szz; II=(sxx*syy)+(sxx*szz)+(syy*szz)-(pow(sxy,2))-(pow(sxz,2))-(pow(syz,2)); III=(sxx*syy*szz)-(sxx*pow(syz,2))-(syy*pow(szz,2))-(szz*pow(sxy,2))+(2*sxy*szz*syz);/*代数方程系数的求解*/ cout,c++,C++,编译器会告诉您错误是什么,以及错误在哪里: a.cpp:40:73: error: expected unqualified-id before '{' token double nrmethod(int r1, double fr1, double dr1fr1, int imax, double es);{

编译器会告诉您错误是什么,以及错误在哪里:

 a.cpp:40:73: error: expected unqualified-id before '{' token                 
 double nrmethod(int r1, double fr1, double dr1fr1, int imax, double es);{  
                                                                        ^

在本例中,是一个无关的分号。如果你想成为一名程序员,你必须学会注意编译器告诉你的内容。

请。还有,有意义的变量名也会有帮助。你真的认为这些变量名是有意义的吗错误发生了吗?转到错误所在的地方,仔细阅读。你应该看到问题。考虑使用简单的乘法,如<代码> x*x<代码>,而不是所有调用<代码> POW(x,2)。,特别是整数变量。
计算机在括号下放了一个胡萝卜
-它给了你一个健康的零食,鼓励你写更可读的代码;)这个分号可能来自main上面的方法定义的复制和粘贴…修复后-有大量编译器警告。在该函数中
fr1
被隐藏。
I
不在范围内……代码混乱,应该抛出away@Ed我完全同意这种观点;我只是想回答OP的标题问题。幸运的是,我不打算成为一名程序员。这只是必修课。分号就是问题所在。非常感谢。此外,通过一些调整,代码最终也成功了。