我正在做家庭作业,我遇到了一些奇怪的事情。我有三个文件:Lab3.c、Lab3.h 和 driver.c。driver.c 正在从 Lab3.c 调用一个方法,但未能将值传递给该方法。
// code from driver.c
float cyRad, cyHt;
printf("Enter a radius for the cylinder: ");
scanf("%f", &cyRad);
printf("%f\n", cyRad);
printf("Enter a height for the cylinder: ");
scanf("%f", &cyHt);
float cyVol = cylinder(cyRad, cyHt);
printf("Cylinder volume: %f\n", cyVol);
// code from Lab3.c
float cylinder(float radius, float height)
{
printf("%f %f %f\n", M_PI, height, radius);
return M_PI * height * pow(radius, 2);
}
// code from Lab3.h
#ifndef __LAB3_H
#define __LAB3_H
extern void sphere(float radius, float *surface, float *volume);
extern float volCylinder(float radius, float height);
extern double sumFloats(double x[], int numFloats);
extern double sine(float angle);
#endif
这是输出:
Enter a radius for the cylinder: 13
13.000000
Enter a height for the cylinder: 45
3.141593 0.000000 0.000000
Cylinder volume: 0.000000
我不知道为什么它没有将值传递给方法cylinder
。任何和所有的帮助将不胜感激。