//Hydroelectric Dam Helper
#include <stdio.h>
#define GRAV 9.80
#define EFINC 0.9
#define EFINC2 90
int main()
{
//Defines all the variables to be used
double height, work, mass;
printf("Height of dam (in meters):");
scanf("%lf", &height);
printf("Flow of water (in thousand cubic meters per second):");
scanf("%lf", &mass);
work = (mass * GRAV * height * EFINC);
printf("The dam would produce %f megawatts at %d%% efficency", &work, EFINC2);
return 0;
}
值设置正确,我通过打印高度和质量来测试它,但 work 从未收到值,EFINC2 打印出一个我不太确定的荒谬数字
最佳答案
printf("The dam would produce %f megawatts at %d%% efficency", &work, EFINC2);
应阅读:
printf("The dam would produce %f megawatts at %d%% efficency", work, EFINC2);
&work
是指向工作的指针,即 double*
但要让 printf
打印您需要传递的值 double
而不是指针。在您的平台上,double*
可能与 double
大小不同,导致后续 printf
格式使用错误数据。
关于c - C 中的变量乘法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3135761/