小编Eli*_*eth的帖子

打印在一个函数中的值工作正常,但在下一个函数中打印错误(返回0.00)

我对此很新,所以请耐心等待.对于编码C类,我们总共使用九个函数和一个头文件(我们称之为my.h)来收集房间的长度和宽度(int),折扣百分比(也是一个int) ),和地毯的单价(双倍).我们将使用输入来计算安装地毯的总成本.我可以得到打印的长度,宽度和面积,但不是单价.它从Read_Data.c和Calc_Value.c函数打印frin,但不在Install_Calice.c中调用,而是在Calc_Value.c中调用.unit_price与长度和宽度同时读取,但不知何故,它没有正确传递.我不知道为什么.也许它需要一个不同的指针.任何帮助都会非常感激.我已经阅读了我的书,并与我的教授和同学交谈,并在互联网上搜索,但我找不到任何有用的东西.Install_Price的代码是:

/*This function calculates the cost of the carpet and the labor cost in order to    
calculate the installed price.*/

#include "my.h"

void Install_Price (int length, int width, int unit_price, int* area, 
double* carpet_cost, double* labor_cost, double* installed_price)

{

printf("\nThe unit price is %7.2f.\n", *unit_price);

*area = length * width;
*carpet_cost = (*area) * unit_price;

printf("The carpet cost is %7d x %7.2f = %7.2f.\n", *area, unit_price, *carpet_cost);

*labor_cost = (*area) * LABOR_RATE;
*installed_price = (*carpet_cost) + (*labor_cost);

return;
} …
Run Code Online (Sandbox Code Playgroud)

c printf pointers function-pointers

1
推荐指数
1
解决办法
183
查看次数

标签 统计

c ×1

function-pointers ×1

pointers ×1

printf ×1