C++ 中的间接间接无效

发布于 2024-11-25 13:43:40 字数 1641 浏览 0 评论 0原文

这是我的程序。我不知道下一步该做什么,因为我不知道什么是无效间接。错误出现在第46行到第52行。

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>


int main()
{
int d, c;

double fx, fx1, fx2, fx3, fd, fd1, fd2, fd3, x, xi, e, y, er;

double in[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

clrscr();


cout << "\n\nEnter degree: ";

cin >> d;

if(d == 9)
{
    cout << "\n\nThis is only limited up to the dehree of 8.";
}

else if(d == 0)
{
    cout << "\n\nCannot solve equation. There is no variable present.";
}

else
{

    for(c = d; c >= 0; c--)
    {
        cout << "\nCoeff for x^" << c << " term: ";
        cin >> in[c];
    }

    cout << "\n\nEnter xi = ";
    cin >> x;

    do
    {
        **fx1 = (c[8] * pow(x,8)) + (c[7] * pow(x,7)) + (c[6] * pow(x,6));
        fx2 = (c[5] * pow(x,5)) + (c[4] * pow(x,4)) + (c[3] * pow(x,3));
        fx3 = (c[2] * pow(x,2)) + (c[1] * x) + c[0];
        fx = (fx1 + fx2 + fx3);

        fd1 = (d * c[0] * pow(x, d-1)) + ((d-1) * c[1] * pow(x, d-2)) + ((d-2) * c[2] * pow(x, d-3));
        fd2 = ((d-3) * c[3] * pow(x, d-4)) + ((d-4) * c[4] * pow(x, d-5)) + ((d-5) * c[5] * pow(x, d-6));
        fd3 = ((d-6) * c[6] * pow(x, d-7)) + (c[7]);**

        fd = (fd1 + fd2 + fd3);

        y = x;

        x = (x - (fx/fd));

        e = x - y;

        if(e >=0)
        {
            er = e;
        }

        else
        {
            er = -(e);
        }
    }while(er > 0.0000000001);

    cout << "\n\nThe root of the equation is " << x << ".";



}



getch();


return 0;
}

This is my program. I dont know what to do next because I dont know what is invalid indirection. The error is found from line 46 to 52.

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>


int main()
{
int d, c;

double fx, fx1, fx2, fx3, fd, fd1, fd2, fd3, x, xi, e, y, er;

double in[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

clrscr();


cout << "\n\nEnter degree: ";

cin >> d;

if(d == 9)
{
    cout << "\n\nThis is only limited up to the dehree of 8.";
}

else if(d == 0)
{
    cout << "\n\nCannot solve equation. There is no variable present.";
}

else
{

    for(c = d; c >= 0; c--)
    {
        cout << "\nCoeff for x^" << c << " term: ";
        cin >> in[c];
    }

    cout << "\n\nEnter xi = ";
    cin >> x;

    do
    {
        **fx1 = (c[8] * pow(x,8)) + (c[7] * pow(x,7)) + (c[6] * pow(x,6));
        fx2 = (c[5] * pow(x,5)) + (c[4] * pow(x,4)) + (c[3] * pow(x,3));
        fx3 = (c[2] * pow(x,2)) + (c[1] * x) + c[0];
        fx = (fx1 + fx2 + fx3);

        fd1 = (d * c[0] * pow(x, d-1)) + ((d-1) * c[1] * pow(x, d-2)) + ((d-2) * c[2] * pow(x, d-3));
        fd2 = ((d-3) * c[3] * pow(x, d-4)) + ((d-4) * c[4] * pow(x, d-5)) + ((d-5) * c[5] * pow(x, d-6));
        fd3 = ((d-6) * c[6] * pow(x, d-7)) + (c[7]);**

        fd = (fd1 + fd2 + fd3);

        y = x;

        x = (x - (fx/fd));

        e = x - y;

        if(e >=0)
        {
            er = e;
        }

        else
        {
            er = -(e);
        }
    }while(er > 0.0000000001);

    cout << "\n\nThe root of the equation is " << x << ".";



}



getch();


return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初见 2024-12-02 13:43:40

有道理,变量c不是数组而是int,但是有c[8],c[6]等。

makes sense, variable c is not an array but an int, but there are c[8], c[6], etc.

小糖芽 2024-12-02 13:43:40

您看到这一点是因为您正在使用 c(一个整数)作为数组/指针。发生间接错误是因为您错误地取消引用非指针的内容。

You're seeing this because you're using c, which is an integer, as an array/pointer. The indirection error occurs because you're incorrectly dereferencing something that is not a pointer.

梦中楼上月下 2024-12-02 13:43:40

您必须使用相同的数组名称,即 in[] 而不是 c[],并在每个变量之前删除 **。

you must use same array name i.e in[] instead of c[] and also remove ** before every variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文