1.あなたの関数のシグネチャは、3つの引数を取り、あなただけそれがコンパイル方法1.を供給し、私はそれが必要とは思わないと、分かりません。
CalculateAirTime
関数は、変数を計算する前に出力します。実際の放送時間をprintf("Total air time: %f\n", time);
をした後、計算:あなたは、最初にこれを行うtime = ((2*velocity)*sin(angle)/GRAVITY);
3.をアドバイスとして、CalculateAirTime
関数が計算された時間を返すために、速度や角度を必要とするため、パラメータとして時間を渡しません。無駄だ。関数内でdouble変数を宣言するか、計算時間を直接返すことができます。
double CalculateAirTime(double velocity, double angle){...}
* EDITでdouble CalculateAirTime(double velocity, double angle, double time){...}
を交換してください!ここで明確にするため は、私はおそらくあなたのプログラムを書く方法は以下のようになります**
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
#define GRAVITY 9.8
/*
I renamed some variables. Just from the variable names, I think you do not understand the solution
for this "air time" problem well. I might be mistaken tough. If you have any questions, please
ask them. You are not leaving this place until you fully understand what is happening.
*/
// Function DECLARATION:
double CalculateAirTime(double Initial_Velocity, double Launch_Angle);
int main(void)
{
// variables
double Initial_Velocity;
double Launch_Angle;
// Initial_Velocity = 20.0 should work aswell. This is called a cast. You will learn about it later
Initial_Velocity = (double)(20.0);
// Converting 45 degrees to radians, because the sin() library function works with radians
Launch_Angle = (double)((45.0/180.0)*PI);
//Call function using our declared values as input
CalculateAirTime(Initial_Velocity,Launch_Angle);
return 0;
}
// Function DEFINITION
//Try to use the same name for paramaters here, as you did in the declaration!
double CalculateAirTime(double Initial_Velocity, double Launch_Angle)
{
double Air_Time;
Air_Time = (double)((2*Initial_Velocity)*sin(Launch_Angle)/GRAVITY);
printf("Total air time: %f\n", Air_Time));
return time;
}
あなたの機能は3つの引数を持っていますが、一つだけを供給しますか? – Li357
'sin()'は度ではなくラジアンで引数を取ることに注意してください。 – timrau
何が問題なのですか? –