#include <stdio.h>
#include <math.h>
#define G 9.81
typedef struct
{
double weight;
double drag;
double time;
} USER_INPUT;
double calculateVelocity(USER_INPUT);
int main(int argc, char **argv)
{
USER_INPUT userInput;
double velocity;
printf("Please enter weight, drag and time: ");
scanf("%lf %lf %lf", &userInput.weight, &userInput.drag, &userInput.time);
velocity = calculateVelocity(userInput);
printf("At t = %f , the parachutist with weight %d kg\nand a drag coefficient %8.2f kg/s \n will have a velocity of %8.2f m/s^2", &userInput.time, &userInput.weight, &userInput.drag, velocity);
return 0;
}
double calculateVelocity(USER_INPUT data)
{
double velocity;
// TODO compute velocity
return velocity;
}
在主函数中,我想显示结果。 如何打印结构中定义的变量? 我试过%f
,它返回0.000000,而%d
返回一个随机数。如何在结构中打印变量?
从代码中,我看到变速不是以任何方式计算或分配的。使用%f打印时,使用%f和垃圾值打印时会得到0.000。你能分享你的公式来计算速度吗? –
可能使用'userInput.time,userInput.weight,... etc.'?注意你的'calculateVelocity'返回一个不确定的值,从中读取是未定义的行为。 – greatwolf