C中的变量乘法?

Jar*_*ner 1 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; 
}
Run Code Online (Sandbox Code Playgroud)

这些值设置正确,我通过打印高度和质量来测试它,但是工作永远不会得到一个值,EFINC2打印出一个我不太确定的荒谬数字

CB *_*ley 7

printf("The dam would produce %f megawatts at %d%% efficency", &work, EFINC2);
Run Code Online (Sandbox Code Playgroud)

应该读:

printf("The dam would produce %f megawatts at %d%% efficency", work, EFINC2);
Run Code Online (Sandbox Code Playgroud)

&work是指向工作的指针,即double*用于printf打印传递a double而不是指针所需的值.在您的平台上,a double*可能double与后续printf格式使用错误数据的大小不同.