首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++中的间接寻址无效

C++中的间接寻址无效
EN

Stack Overflow用户
提问于 2011-07-24 14:12:00
回答 3查看 16.1K关注 0票数 1

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

代码语言:javascript
复制
#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;
}
EN

回答 3

Stack Overflow用户

发布于 2011-07-24 14:18:37

您之所以看到这一点,是因为您使用c作为数组/指针,这是一个整数。发生间接错误是因为您错误地取消了对非指针对象的引用。

票数 4
EN

Stack Overflow用户

发布于 2011-07-24 14:19:24

有道理,变量c不是一个数组,而是一个整数,但有c8、c6等。

票数 4
EN

Stack Overflow用户

发布于 2016-08-21 17:22:32

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6805254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档