gpt4 book ai didi

c++ - 更新链表时遇到问题

转载 作者:行者123 更新时间:2023-11-28 05:41:26 24 4
gpt4 key购买 nike

<分区>

class MostBought {        //class in a .h file
private:
typedef struct node {
double moneySpent;
char Name[50];
node *next;
} * nodePtr3;

nodePtr3 head3;
nodePtr3 curr3;
nodePtr3 temp3;
nodePtr3 next3;

public:
MostBought();
void addMoney(double x, char Category[50]);
void PrintList();
};

MostBought::MostBought() { //everything else in main.cpp
head3 = NULL;
curr3 = NULL;
temp3 = NULL;
next3 = NULL;
}


void MostBought::addMoney(double x, char Category[50]) {
temp3 = head3;
while (temp3 != NULL) {
if (temp3->Name == Category) {
temp3->moneySpent = temp3->moneySpent + x;
}
else {
temp3 = temp3->next;
}
}
}

我像这样在 main() 中调用 addMoney“addMoney(aa.Price, aa.Category)”,其中 aa 是一个结构对象。程序可以编译,但是当我尝试打印所有节点及其名称和值时,所有值都等于 0。知道出了什么问题吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com