c - C 中的变量乘法?

标签 c variables constants multiplication

//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/

相关文章:

c - 为什么我的代码无法使用 sprintf 和 fopen 打开新文件?

去除相关矩阵中的 NA

javascript - 拦截javascript中的全局变量定义

c++ - 重载参数列表中与原始函数仅相差 "const"的函数

c++ - 将 Image*[3] 传递给 const Image*[3] 不能用 const_cast<Image*[3]> 完成,替代方案?

c++ - 什么时候使用 const string& 与 const string 比较好

c - nan 使用带有 math.h 函数的 long double 返回

c - 使用管道在两个子进程之间持续通信

c++ - 错误 C2057 : expected constant expression

c++ - const 变量究竟是什么?