【发布时间】:2019-04-07 11:53:26
【问题描述】:
我不知道如何使用调试器,我想我没有 所以我试图在 C++ Called Product 中创建简单的链表 此列表将用于存储产品... 我已经做了一个函数,可以在列表的开头添加一个新节点 并且还制作了一个名为“Afficher1”的无效函数,它应该向我显示列表中的产品总数及其总价(不含增值税) 以及增值税总额和最终总额(含增值税) 但是当我在主函数中调用 void 时,它不会运行它只是用返回值完成主执行!=0
当我删除函数内部的一些操作时,例如:
double total_TVA=((total)*(temp->TVA))/(100.0); 双TTC=total+total_TVA;
#include<iostream>
#include<string>
using namespace std;
struct Product{
string code_prod;
string designation;
string UM;
double PUA_HT;
double QTE;
double TVA;
Product *next;
};
Product *head=NULL;
Product *Add_Product(Product* &head, string code, string des, string um, double pua, double qte, double tva){
Product *prod=new Product;
prod->code_prod=code;
prod->designation=des;
prod->UM=um;
prod->PUA_HT=pua;
prod->QTE=qte;
prod->TVA=tva;
prod->next=head;
head=prod;
return head;
}
void Afficher1(){
if(head != NULL){
Product *temp=head;
double total=0;
int i=0;
while(temp != NULL){
total=total + ((temp->PUA_HT)*(temp->QTE));
i++;
temp=temp->next;
}
double total_TVA=((total)*(temp->TVA))/(100.0);
double TTC=total+total_TVA;
cout<<"Nombre total des produits Achetes: "<<i<<endl;
cout<<"Le Montant Total HT: "<<total<<endl;
cout<<"Total TVA de "<<temp->TVA<<" : "<<total_TVA<<endl;
cout<<"Total TTC: "<<TTC<<endl;
}
}
int main(){
Product *head=NULL;
string codes; string dess; string ums; double puas; double qtes; double tvas;
for(int i=0;i<1;i++){
cout<<"Donner les infos pour le proudit "<<i+1<<endl;
cin>>codes;
cin>>dess;
cin>>ums;
cin>>puas;
cin>>qtes;
cin>>tvas;
head=Add_Product(head, codes, dess, ums, puas, qtes, tvas);
}
Afficher1();
return 0;
}
【问题讨论】:
-
想想
temp在while (temp != NULL)循环之后是什么。 -
Afficher1()没有被调用或没有运行似乎极不可能。看看它:你能想象它可能运行的方式,但给你的印象是它没有运行吗? -
获得调试器并学习使用它将对您大有裨益。您甚至可能已经拥有一个,因为大多数 IDE 都包含一个或包含与外部接口的接口,并且大多数操作系统的开发人员工具至少包含一个(例如
gdb)。 -
“我不知道如何使用调试器而且我没有” 这是一个完全不相关的陈述。每个 c++ 工具链都附带一个调试器,您显然应该学习如何使用它。这是每个程序员都需要掌握的基本技能。
-
“我不知道如何使用调试器,我也没有” - 那么你应该获得一个并学习如何使用它。请停止喊叫。
标签: c++ linked-list singly-linked-list