注册 登录
编程论坛 C++教室

求助

kakaqq 发布于 2008-10-09 19:20, 559 次点击
自己看书做的一道题目。可是运行结果不知道是什么东西啊。题目就是计算多项式的值。帮忙看看那错了。
#include <iostream.h>
#include <math.h>
struct node
{int zs,xs;
node* next;};
node *Tail_Create()
{
    node *head,*n,*tail;
    int i,j,m,a;
    head=NULL;
    cout<<"输入多项式项数";
    cin>>m;
    cout<<"输入多项式";
    for(a=0;a<m;a++)
    {   cin>>i>>j;
        n=new node;
        n->xs=i;
        n->zs=j;
        if(!head) tail=head=n;
        else tail->next=n,tail=n;
    }
    if(head) tail->next=NULL;
    return head;
}
sum(int x,node *head)
{
    double ggyy=0;
    while(head)
    {ggyy+=head->xs*pow(x,head->zs);
    head=head->next;}
    cout<<ggyy;
}

void main(void)
{
    node *head;
    int x;
    head=Tail_Create();
    cout<<"输入未知数x的值";
    cin>>x;
    cout<<sum(x,head);}
2 回复
#2
blueboy820062008-10-09 22:24
你 sum 都没有返回值!
你cout<<sum(x,head);
能输出个什么????
#3
kakaqq2008-10-10 19:17
哦是了····多了···sum里面有cout,哎···脑袋不好使啊·
1